#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int main() {
  int k, p;
  scanf("%d %d", &k, &p);
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    long long tmp = i % p;
    for (long long j = i; j > 0; j /= 10) (tmp = tmp * 10 + j % 10) %= p;
    (ans += tmp) %= p;
  }
  printf("%I64d\n", ans);
  return 0;
}
