#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
//mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,T y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,T y){if(x>y)x=y;}
inline int read(){
  #define nc getchar()
  bool f=0;int x=0;char c=nc;
  while(c<48)f|=c=='-',c=nc;
  while(c>47)x=x*10+(c^48),c=nc;
  return f?-x:x;
  #undef nc
}

typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll N;int M;

int qp(int a,ll k,int P){
  int res=1;
  for(;k;k>>=1,a=1ll*a*a%P)if(k&1)res=1ll*res*a%P;
  return res;
}

void solve(){
  cin>>N>>M;
  int tp=qp(10%M,N,M);
//  printf("#%d\n",tp);
  int val=qp(10%(M*M),N,M*M);
//  printf("#%d\n",val);
  val=(val-tp+M*M)%(M*M);
  if(val==0){
    puts("0");
  }else{
    cout<<(val/M)%M<<endl;
  }
//  ((10^n-tp)/M)%M;
}

signed main(){
//  int T=read();
//  while(T--)solve();
  solve();
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const ll MAX = 50000000000000;
ll MOD = 1000000007;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll N,M,a;
    cin >> N >> M;
    a = modpow(10,N,M * M);
    a /= M;
    cout << a % M << endl;
}
