#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  long long k, p;
  cin >> k >> p;
  long long init = 11, sum = 0;
  long long val = 11;
  long long len = 2;
  for (long long i = 1; i <= k; i++) {
    sum += init;
    init += val;
    vector<long long> v;
    long long x = init;
    while (x != 0) {
      v.push_back(x % 10);
      x = x / 10;
    }
    if (i == k) {
      break;
    }
    reverse(v.begin(), v.end());
    if (v[len / 2] == 9) {
      long long idx = (len - 1) / 2;
      sum += init;
      i++;
      while (idx >= 0 && v[idx] == 9) {
        v[idx] = 0;
        v[len - 1 - idx] = 0;
        idx--;
      }
      if (v[0] == 0) {
        len += 2;
        val *= 10;
        init = pow(10, len - 1) + 1;
      } else {
        v[idx]++;
        v[len - 1 - idx]++;
        long long cnt = 0;
        init = 0;
        for (int i = len - 1; i >= 0; i--) {
          init += (pow(10, cnt) * v[i]);
          cnt++;
        }
      }
    }
  }
  cout << sum % p << '\n';
}
