#include using namespace std; typedef long long ll; ll mod = 1000000007; ll pw(ll a,ll x,ll y){ ll ret = 1; while(x){ if(x&1) (ret *= a) %= y; x /= 2; (a *= a) %= y; } return ret; } int main(){ ll p,k; cin >> p >> k; k = pw(10,p - 2,p); ll ans = (pw(10,p - 1,mod) + mod - 1)%mod*pw(p,mod - 2,mod)%mod; if(k==0) ans++; cout << ans << endl; }