#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll Modpow(ll k,ll n,ll m){
    if(n==0){
        return 1;
    }else if(n%2==0){
        ll t=Modpow(k,n/2,m);
        return (t*t)%m;
    }else{
        return (Modpow(k,n-1,m)*k)%m;
    }
}
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans=(Modpow(10,n,m*m)/m)%m;
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

long long n, m;
vector<long long> ten;
vector<vector<long long>> memo, sum;

int main() {
  cin >> n >> m;
  ten.push_back(10 % m);
  for (int i = 0; i < 62; ++i) {
    long long now = ten.back() * ten.back() % m;
    ten.push_back(now);
  }
  memo.assign(62, vector<long long>(m, 0));
  sum.assign(62, vector<long long>(m, 0));
  for (int i = 0; i < m; ++i) memo[0][i] = (i * 10) % m;
  for (int i = 0; i < m; ++i) sum[0][i] = (i * 10) / m % m;
  for (int i = 0; i < 60; ++i)
    for (int j = 0; j < m; ++j) {
      memo[i + 1][j] = memo[i][memo[i][j]];
      sum[i + 1][j] = (sum[i][j] * ten[i] + sum[i][memo[i][j]]) % m;
    }
  long long res = 0, now = 1;
  for (int i = 0; i < 60; ++i)
    if (n >> i & 1) {
      res = (res * ten[i] + sum[i][now]) % m;
      now = memo[i][now];
    }
  cout << res << endl;
  return 0;
}