#include<map>
#include<set>
#include<stack> 
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>

#define NZB  ios::sync_with_stdio(false)

typedef long long ll;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int MAX_N = 1e3 + 7;

using namespace std;

int a[MAX_N], b[MAX_N];
int dp[MAX_N][MAX_N];

int main()
{
	NZB;
	int N, M;
	cin>>N>>M;
	for(int i=1;i<=N;i++) cin>>a[i];
	for(int i=1;i<=M;i++) cin>>b[i];
	memset(dp, 63, sizeof(dp));
	for(int i=0;i<=N;i++) {
		for(int j=0;j<=M;j++) {
			if(!i || !j) {
				dp[i][j] = max(i, j);
				continue;
			}
			dp[i][j] = min(dp[i][j-1], dp[i-1][j]) + 1;
			if(a[i] == b[j]) dp[i][j] = min(dp[i][j], dp[i-1][j-1]);
			else dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1);
			//printf("(%d,%d,%d)", i,j ,dp[i][j]);
		}
	}
	cout<<dp[N][M]<<endl;
}
#include<bits/stdc++.h>

using namespace std;

long long n,L,A[2];

string s[200005];

int main() {	
    cin>>n>>L;
    for(int i=1;i<=n;i++) 
    	cin>>s[i];
    A[0]=1;	
    for(int i=2;i<=n;i++) {
    	int cnt=0;
    	for(int j=0;j<L;j++) 
    		if(s[i][j]!=s[1][j]) 
    			cnt++;
    	A[cnt%2]++;
 	} 	
 	cout<<A[0]*A[1];
	return 0; 
   }