#include <bits/stdc++.h>
using namespace std;
long long powt[13];
vector<long long> vec;
vector<long long> pre;
void solve(int nod, int cd, long long val) {
  if (cd == (nod / 2)) {
    if (cd == 1) {
      for (int i = 1; i <= 9; i++) {
        vec.push_back(val + i * 1ll * powt[nod - cd] + i * 1l * powt[cd - 1]);
      }
    } else {
      for (int i = 0; i <= 9; i++) {
        vec.push_back(val + i * 1ll * powt[nod - cd] + i * 1l * powt[cd - 1]);
      }
    }
    return;
  }
  if (cd == 1) {
    for (int i = 1; i <= 9; i++) {
      solve(nod, cd + 1,
            val + i * 1ll * powt[nod - cd] + i * 1l * powt[cd - 1]);
    }
  } else {
    for (int i = 0; i <= 9; i++) {
      solve(nod, cd + 1,
            val + i * 1ll * powt[nod - cd] + i * 1l * powt[cd - 1]);
    }
  }
}
int main() {
  powt[0] = 1;
  for (int i = 1; i <= 10; i++) {
    powt[i] = (powt[i - 1] * 10);
  }
  int k, p;
  scanf("%d %d", &k, &p);
  solve(2, 1, 0);
  solve(4, 1, 0);
  solve(6, 1, 0);
  solve(8, 1, 0);
  solve(10, 1, 0);
  vec.push_back(100000000001);
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    if (pre.size() == 0) {
      pre.push_back(vec[0] % p);
    } else {
      pre.push_back((pre.back() + vec[i]) % p);
    }
  }
  printf("%lld\n", pre[k - 1]);
  return 0;
}
