#include <bits/stdc++.h>
using namespace std;
bool ispal(string a) {
  int n = a.size();
  if (n % 2 == 0) {
    for (int i = 0; i < n / 2; i++)
      if (a[i] != a[n - 1 - i]) return 0;
    return 1;
  }
  return 0;
}
void solve() {
  long long k, p, c = 0;
  cin >> k >> p;
  for (int i = 1; i <= k; i++) {
    long long tmp1 = i, tmp2 = i;
    while (tmp2 > 0) {
      tmp1 = tmp1 * 10 + tmp2 % 10;
      tmp1 %= p;
      tmp2 /= 10;
    }
    c = (c + tmp1) % p;
  }
  cout << c << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
