#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
const int P = 1e9 + 7;
const int M = 52;
struct Matrix {
array<array<int, M>, M> arr;
Matrix() {
REP (i, M) {
REP (j, M) {
arr[i][j] = 0;
}
}
}
array<int, M>& operator[](int a) { return arr[a]; }
Matrix operator*(Matrix Q) {
Matrix R;
REP (i, M) {
REP (j, M) {
REP (k, M) {
R[i][j] = (R[i][j] + arr[i][k] * Q[k][j]) % P;
}
}
}
return R;
}
};
Matrix Pow(Matrix A, int b) {
Matrix R = A;
b--;
while (b) {
if (b % 2) {
R = R * A;
}
A = A * A;
b /= 2;
}
return R;
}
int spow(int a, int b) {
int r = 1;
while (b) {
if (b % 2) {
r = r * a % P;
}
a = a * a % P;
b /= 2;
}
return r;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
cin.tie(0);
//double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
int L, A;
cin>>L>>A;
int all = -1;
VI at_most(A + 1);
RE (cap, A) {
//vector<int> v(M);
//v[1] = A;
Matrix Q;
REP (i, cap + 1) {
Q[0][i] = 1;
Q[1][i] = (i > 0);
}
FOR (i, 2, cap) {
Q[i][i - 1] = A - i + 1;
FOR (j, i, cap) {
Q[i][j] = 1;
}
}
Q = Pow(Q, L);
//res = (res + Q[0][1]) % P;
at_most[cap] = Q[0][1];
debug(cap, Q[0][1]);
}
VI exact(A + 1);
RE (cap, A) {
exact[cap] = (at_most[cap] - at_most[cap - 1] + P) % P;
}
int R = 0;
RE (cap, A) {
R = (R + cap * exact[cap]) % P;
}
cout<<R * spow(at_most[A], P - 2) % P<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTVAgbWFrZV9wYWlyCiNkZWZpbmUgUEIgcHVzaF9iYWNrCiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIHN0IGZpcnN0CiNkZWZpbmUgbmQgc2Vjb25kCiNkZWZpbmUgcmQgdGhpcmQKI2RlZmluZSBGT1IoaSwgYSwgYikgZm9yKGludCBpID0oYSk7IGkgPD0oYik7ICsraSkKI2RlZmluZSBSRShpLCBuKSBGT1IoaSwgMSwgbikKI2RlZmluZSBGT1JEKGksIGEsIGIpIGZvcihpbnQgaSA9IChhKTsgaSA+PSAoYik7IC0taSkKI2RlZmluZSBSRVAoaSwgbikgZm9yKGludCBpID0gMDtpIDwobik7ICsraSkKI2RlZmluZSBWQVIodiwgaSkgX190eXBlb2YoaSkgdj0oaSkKI2RlZmluZSBGT1JFKGksIGMpIGZvcihWQVIoaSwgKGMpLmJlZ2luKCkpOyBpICE9IChjKS5lbmQoKTsgKytpKQojZGVmaW5lIEFMTCh4KSAoeCkuYmVnaW4oKSwgKHgpLmVuZCgpCiNkZWZpbmUgU1ooeCkgKChpbnQpKHgpLnNpemUoKSkKI2RlZmluZSBfX2J1aWx0aW5fY3R6IF9fYnVpbHRpbl9jdHpsbAojZGVmaW5lIF9fYnVpbHRpbl9jbHogX19idWlsdGluX2NsemxsCiNkZWZpbmUgX19idWlsdGluX3BvcGNvdW50IF9fYnVpbHRpbl9wb3Bjb3VudGxsCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnRlbXBsYXRlPHR5cGVuYW1lIFRIPiB2b2lk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TWF0cml4IFI7CiAgICBSRVAgKGksIE0pIHsKICAgICAgUkVQIChqLCBNKSB7CiAgICAgICAgUkVQIChrLCBNKSB7CiAgICAgICAgICBSW2ldW2pdID0gKFJbaV1bal0gKyBhcnJbaV1ba10gKiBRW2tdW2pdKSAlIFA7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gUjsKICB9Cn07Ck1hdHJpeCBQb3coTWF0cml4IEEsIGludCBiKSB7CiAgTWF0cml4IFIgPSBBOwogIGItLTsKICB3aGlsZSAoYikgewogICAgaWYgKGIgJSAyKSB7CiAgICAgIFIgPSBSICogQTsKICAgIH0KICAgIEEgPSBBICogQTsKICAgIGIgLz0gMjsKICB9CiAgcmV0dXJuIFI7Cn0KCmludCBzcG93KGludCBhLCBpbnQgYikgewogIGludCByID0gMTsKICB3aGlsZSAoYikgewogICAgaWYgKGIgJSAyKSB7CiAgICAgIHIgPSByICogYSAlIFA7CiAgICB9CiAgICBhID0gYSAqIGEgJSBQOwogICAgYiAvPSAyOwogIH0KICByZXR1cm4gcjsKfQppbnQzMl90IG1haW4oKSB7CgogIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgY291dCA8PCBmaXhlZCA8PCBzZXRwcmVjaXNpb24oMTApOwogIGNlcnIgPDwgZml4ZWQgPDwgc2V0cHJlY2lzaW9uKDEwKTsKICBjaW4udGllKDApOwogIC8vZG91YmxlIGJlZ19jbG9jayA9IDEuMCAqIGNsb2NrKCkgLyBDTE9DS1NfUEVSX1NFQzsKICAKICBpbnQgTCwgQTsKICBjaW4+Pkw+PkE7CiAgaW50IGFsbCA9IC0xOwogIFZJIGF0X21vc3QoQSArIDEpOwogIFJFIChjYXAsIEEpIHsKICAgIC8vdmVjdG9yPGludD4gdihNKTsKICAgIC8vdlsxXSA9IEE7CiAgICBNYXRyaXggUTsKICAgIFJFUCAoaSwgY2FwICsgMSkgewogICAgICBRWzBdW2ldID0gMTsKICAgICAgUVsxXVtpXSA9I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