#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 200100
#define MOD 1000000007  //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;


int main() {
	ll n, m,mm, x, y;
	x = (ll)10;
	y = (ll)1;
	cin >> n >> m;
	mm = m * m;
	while (n > 0) {
		if (n & 1)y = (y*x) % mm;
		x = (x*x) % mm;
		n /= 2;
	}
	y /= m;
	cout << y << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

long long binpow(long long i, long long x, long long MOD)
{
    long long rs=1;
    long long a=x;
    while(i)
    {
        if (i&1)
        {
            i--;
            rs*=a;
            rs%=MOD;
        }
        else
        {
            i/=2;
            a*=a;
            a%=MOD;
        }
    }
    return rs%MOD;
}

void solve()
{
    long long n,m;
    cin >> n >> m;
    long long MOD = m*m;

    long long x = binpow(n,10,MOD);
    //cout << x << "\n" ;

    //x+=MOD;
    x = (x-x%m)/m; //cout << x << "\n";
    cout << x-(x%m)/m;
}

int main()
{
int t=1;
//cin >> t;
while (t--) solve();
}
