//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
using namespace std;
int n, m;
int power(int A, int B, int C)
{
    int res = 1;
    A %= C;
    while (B)
    {
        if (B & 1)
        {
            res = res * A % C;
        }
        B >>= 1;
        A = A * A % C;
    }
    return res;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    cout << power(10, n, m * m) / m % m << endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,a) for (int i = 0; i < (a); i++ )
#define Rep(i,start,a) for (int i = start; i < (a); i++ )
#define ALL(vec) (vec).begin(), (vec).end()
#define Sort(vec) sort((vec).begin(), (vec).end()) // 小さい順
#define SORT(vec) sort((vec).begin(), (vec).end(), [](int a, int b){return a>b;}) // 大きい順
#define Sortll(vec) sort((vec).begin(), (vec).end()) // 小さい順
#define SORTll(vec) sort((vec).begin(), (vec).end(), [](long long a, long long b){return a>b;}) // 大きい順
#define debug(x) cout << #x << " = " << (x) << endl
#define VI vector<int>
#define VLL vector<long long>
#define PII pair<int,int>
#define VPII vector<PII>
#define VB vector<bool>
#define Graph vector<vector<int>>
#define PB push_back
#define USI unordered_set<int>
typedef long long ll;
// const int mod = 998244353;
// const int MOD = 1000000007;
const ll INFLL = (1LL << 62) -1;
const int INF = (1 << 30) -1;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};
 
using namespace std;


long long modpow(long long x, long long n, ll MOD) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
  
  ll N;
  ll M;
  cin >> N >> M;
  
  ll d = modpow(10,N,M*M);
  cout << (d/M)%M << endl; 

}