#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
int h,i,j,w,x,y,a[105][105],b[105][105];
string s[105];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>h>>w;
	for(;i++<h;)cin>>s[i];
	for(i=0;i++<h;)
	{
		for(j=0;j<w;j++)
		{
			a[i][j+1]=s[i][j]&1;
		}
	}
	for(i=0;i++<h;)
	{
		for(j=0;j++<w;)
		{
			x=b[i-1][j]+(a[i-1][j]<a[i][j]);
			y=b[i][j-1]+(a[i][j-1]<a[i][j]);
			if(i<2)b[i][j]=y;
			else if(j<2)b[i][j]=x;
			else b[i][j]=min(x,y);
			//cout<<b[i][j]<<' ';
		}
		//cout<<endl;
	}
	cout<<b[h][w];
}