#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k, ll p) {
    ll r = 1, t = n % p;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % p;
        t = t * t % p;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2, P);
}

int main() {
    int p, k;
    cin >> p >> k;

    ll s = (powmod(10, p - 1, p) + p - 1 - k) % p;
    ll r = (powmod(10, p - 1, P) + p - 1 - k + (P - s)) % P * modinv(p) % P;

    cout << r << endl;

    return 0;
}