#include<bits/stdc++.h>
using namespace std;

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << " | ";
	err(++it, args...);
}

const ll inf = 1e18;
const int nax = 1e5 + 5;

map<pll,vector<pair<pll, int>> > g;
map<pll,ll>arrival,departure;
ll n,m;

void dijkstra(pll source, pll destination,ll x)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			arrival[{i,j}]=inf;
			departure[{i,j}]=inf;
		}
	}
	arrival[source]=x;

	set<pair<ll, pll> > s;
	s.insert({0, source});
	while(!s.empty())
	{
		auto x = *(s.begin());
		s.erase(x);
		departure[x.second]=arrival[x.second];
		for(auto it:g[x.second])
		{
			if(arrival[it.first] > departure[x.second] + it.second)
			{
				s.erase({arrival[it.first], it.first});
				arrival[it.first]=departure[x.second] + it.second;
				s.insert({arrival[it.first], it.first});
			}
		}
	}
}

bool isvalid(ll x,ll y)
{
	if(x<n && y<m)
	{
		return 1;
	}
	return 0;
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		cin>>n>>m;

		string s[n];
		forn(i,0,n)
		{
			cin>>s[i];
		}

		forn(i,0,n)
		{
			forn(j,0,m)
			{
				if(s[i][j] == '#')	//black
				{
					if(isvalid(i,j+1))
					{
						if(s[i][j+1] == '#')
						{
							g[{i,j}].pb({{i,j+1},0});
						}
						else
						{
							g[{i,j}].pb({{i,j+1},0});
						}
					}
					if(isvalid(i+1,j))
					{
						if(s[i+1][j] == '#')
						{
							g[{i,j}].pb({{i+1,j},0});
						}	
						else
						{
							g[{i,j}].pb({{i+1,j},0});
						}
					}
				}
				else	//white
				{
					if(isvalid(i,j+1))
					{
						if(s[i][j+1] == '#')
						{
							g[{i,j}].pb({{i,j+1},1});
						}
						else
						{
							g[{i,j}].pb({{i,j+1},0});
						}
					}
					if(isvalid(i+1,j))
					{
						if(s[i+1][j] == '#')
						{
							g[{i,j}].pb({{i+1,j},1});
						}	
						else
						{
							g[{i,j}].pb({{i+1,j},0});
						}
					}
				}
			}
		}
		ll x = (s[0][0] == '#');
		dijkstra({0,0},{n-1,m-1},x);
		cout<<arrival[{n-1,m-1}];

	}

	return 0;
}


Measured memory_bytes: 2944