#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int h, w; cin >> h >> w;
	string s[h];
	REP(i, h) cin >> s[i];
	int res = 0;
	REP(i, h-1) REP(j, w-1) {
		int cnt = 0;
		REP(x, 2) REP(y, 2)
			if (s[i+y][j+x] == '#') cnt++;
		if (cnt%2) res++;
	}
	cout << res << '\n';
    return 0;
}

#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define P pair<ll,ll> 
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;

inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


ll dp[1005][1005] ;
int main(){
  ll n,m ; cin>>n>>m ;
  vector<ll> A(n),B(m) ;
  rep(i,n) cin>>A[i] ;
  rep(i,m) cin>>B[i] ;
  rep(i,1005) dp[i][0]=i ;
  rep(i,1005) dp[0][i]=i ;
  rep2(i,1,n)rep2(j,1,m){
    ll p=dp[i-1][j-1] ;
    if(A[i-1]!=B[j-1]) p++ ;
  dp[i][j]=min(min(dp[i-1][j],dp[i][j-1])+1,p) ;
  }
  cout<<dp[n][m]<<endl ;
    return 0 ;
}