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

int modpow(int p, long long n, int mod) {
    if (n == 0) return 1;
    int t = modpow(p, n / 2, mod);
    return n % 2 == 0 ? 1LL * t * t % mod : 1LL * t * t % mod * p % mod;
}
 
int main() {
  long long N;
  int M;
  cin >> N >> M;
  cout << (modpow(10, N, M * M) / M) % M << endl;
}
 
 

#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define INF 0x3f3f3f3f
#define f first
#define s second
#define FOR(i, n) for(int i = 1; i <= n; i ++)
#define FFOR(i, a, b) for(int i = a; i <= b; i ++)
#define pii pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mem(x, a) memset(x, a, sizeof(x))
#define loli ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int maxn = 1e6 + 50;
int n, m;
unordered_set<int> st;
vector<int> vc;

signed main(){
	loli;
	cin >> n >> m;
	int t = 1LL;
	st.reserve(10000000);
	while(1) {
		if(st.find(t) != st.end()) {
			break;
		}
		else {
			st.insert(t);
			vc.pb(t);
		}
		t = t * 10LL % (m * m);
	}
	//cout << t << "\n";
	//cout << st.size() << "\n";
	//for(int i : vc) cout << i << " "; cout << "\n";
	int i = 0;
	for(; i < (int)vc.size(); i ++) if(vc[i] == t) break;
	//cout << "aaa" << i << "\n";
	if(n < i) {
		cout << vc[n] / m << "\n";
		return 0;
	}
	n -= i;
	int ssz = (int)vc.size() - i;
	int tans = vc[n % ssz + i] / m;
	cout << tans << "\n";
}

