#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int N=2e3+100,INF=0x3f3f3f3f;
char g[N][N];
int st[N][N];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	scanf("%s",g[i]+1);
	int ans=0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			if(g[i][j]!=g[i+1][j]){
				if(st[i][j-1]==0)
				ans++;
				st[i][j]=1;
			}
		}
	}
	
	memset(st,0,sizeof st);
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			if(g[i][j]!=g[i][j+1]){
				if(st[i-1][j]==0)
				ans++;
				st[i][j]=1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
#define in insert
#define ff first
#define ss second
#define vt vector
#define up upper_bound
#define lb lower_bound
#define repp(i,n,a) for(int i = n; i >= a; i--)
#define re(a,n) rep(i,0,n) cin>>a[i];
const long double pi = 2 * acos(0.0);
const int mod = 1e9 + 7;
const int maxn = 2e5+5;




void solve(){
    int x,y;
    cin>>x>>y;
    if(x==y){
        cout<<x;
    }else{
        cout<<(3-(x+y)%3)%3;
    }





    

    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    
    
    return 0;
}