#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    ll mod = m * m;
    ll ans = 1, temp = 10 % mod;
    while (n) {
        if (n & 1) {
            ans *= temp;
            ans = ans % mod;
        }
        n >>= 1;
        temp = temp * temp % mod;
    }
    cout << ans / m << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std ;

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) (v).begin() , (v).end() , comp

# define ll long long

# define line cout << "\n" ;
# define fast ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ;

# define pii pair < int , int >
# define pll pair < ll , ll >

# define F first
# define S second

const int dx[] = { -1 , 0 , 1 , 0 , -1 , -1 , 1 , 1 } ;
const int dy[] = { 0 , 1 , 0 , -1 , -1 , 1 , -1 , 1 } ;

ll n , m , mod ;

ll mult ( ll a , ll b )
{
    a *= b ;
    a %= mod ;

    return a ;
}

int mod_pow ( ll a , ll b )
{
//    cout << "a : " << a << " and b : " << b ; line ;
//    getchar() ;

    if ( b == 0 ) return 1 ;
    if ( b == 1 ) return a%mod ;
    if ( b == 2 ) return mult ( a , a ) ;

    return mult ( mod_pow ( mod_pow ( a , b/2 ) , 2 ) , mod_pow ( a , b%2 ) ) ;
}

void solve ( int test_case )
{
    cin >> n >> m ;
    mod = m * m ;

//    cout << "mod : " << mod ; line ;
//    cout << "n : " << n ; line ;

    ll ans = mod_pow ( 10 , n ) ;
//    cout << "ans : " << ans ; line ;

    ans /= m ;
    ans %= m ;

    cout << ans ; line ;
}

int main()
{
    int t = 1 ;
    // cin >> t ;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0 ;
}
