import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int k, p;
    scan(k, p);

    if (p == 1) {
        writeln(0);
        return;
    }

    long ans;

    foreach (i ; 1 .. k + 1) {
        long zcy = 1L * i * 10L^^(digit(i)) + revnum(i);
        (ans += zcy) %= p;
    }

    writeln(ans);
}

int digit(int num) {
    return num > 0 ? digit(num / 10) + 1 : 0;
}

long revnum(long n) {
    long res;

    while (n > 0) {
        res *= 10;
        res += (n % 10);
        n /= 10;
    }

    return res;
}

unittest {
    assert(revnum(0) == 0);
    assert(revnum(8) == 8);
    assert(revnum(10) == 1);
    assert(revnum(123) == 321);
    assert(revnum(10100) == 101);
    writeln("ok");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}