#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;

// 
struct Edge {
    int to;
    long long w;
    Edge(int to, long long w) : to(to), w(w) {}
};

// Union find
struct dsu {
    vector<int> d;
    dsu(int n = 0): d(n,-1) {}
    int findRoot(int x) {
        if(d[x] < 0) return x;
        return d[x] = findRoot(d[x]);
    }
    bool unite(int x,int y) {
        x = findRoot(x); y = findRoot(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return findRoot(x) == findRoot(y);}
    int size(int x) {return -d[findRoot(x)];}
};

#include <iostream>
using namespace std;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

/*
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
*/

template <typename T>
T my_lower_bound(vector<T> a, T lb, T ub, T k) {
    while(ub - lb > 1) {
        T mid = (lb + ub) / 2;
        if(a[mid] >= k) {
            ub = mid;
        }else{
            lb = mid;
        }
    }
    return ub;
}

//change a large letter into a small letter
char chupper(char a) {
    a += ('A' - 'a');
    return a;
}

//change a small letter into a large letter
char chlower(char a) {
    a += ('a' - 'A');
    return a;
}

template <class T> void chmin(T &a, T b){
    if(a > b){
        a = b;
    }
}

template <class T> void chmax(T &a, T b){
    if(a < b){
        a = b;
    }
}

int main() {
    ll n; int m;
    cin >> n >> m;
    cout << modpow(10,n,m * m) / m % m << endl;
    return 0;
}

/*
* @Author: kabbo
* @Date:   2020-06-24 08:40:07
* @Last Modified by:   kabbo
* @Last Modified time: 2020-06-24 08:49:58
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<long long,long long>
#define endl '\n'
#define ull unsigned long long
#define ll int64_t
#define ar array
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun>
class y_combinator_result {
	Fun fun_;
public:
	template<class T>
	explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

	template<class ...Args>
	decltype(auto) operator()(Args &&...args) {
		return fun_(std::ref(*this), std::forward<Args>(args)...);
	}
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
	return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
#define sc1(x) scanf("%lld",&(x));
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int dp[1005][1005];
vector<int>a,b;
int sol(int i,int j){
    	if (i == -1 and j == -1)return 0;
		if (i == -1)return j + 1;
		if (j == -1)return i + 1;
		int &ret = dp[i][j];
		if (ret != -1)return ret;
		int op1 = sol(i - 1, j) + 1;
		int op2 = sol(i, j - 1) + 1;
		int op3 = sol(i - 1, j - 1) + (a[i] != b[j]);
		return ret = min({op1, op2, op3});
}
void solve() {
	int n, m;
	cin >> n >> m;
	a.resize(n),b.resize(m);
	for (auto& x : a)cin >> x;
	for (auto& x : b)cin >> x;
	
	memset(dp, -1, sizeof(dp));
	cout<<sol(n-1,m-1)<<endl;
// 	auto res = y_combinator([&](auto sol, int i, int j)->int {
// 	
// 	})(n-1,m-1);
//      cout<<res<<endl;


}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	/*int t;
	cin >> t;
	for (int i(1); i <= t; ++i) {
		printf("Case %d:\n", i);*/
	solve();
	//}
	return 0;
}