//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

map<p32, int> idx;
map<int, p32> inv_idx;
map<p32, int> wt;

bool check(int i, int j, int n, int m)
{
	if (i >= 1 && j >= 1 && i < n && j < m)
		return true;
	return false;
}

void construct_graph(vector<v32> &mat, graph &g)
{
	int n = mat.size();
	int m = mat[1].size();
	int curr = 1;
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			idx[{i, j}] = curr;
			inv_idx[curr++] = {i, j};
		}
	}
	//debug("hell");
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			if (check(i, j + 1, n, m))
			{
				g[idx[{i, j}]].push_back(idx[{i, j + 1}]);
				wt[{idx[{i, j}], idx[{i, j + 1}]}] = ((mat[i][j] == 0 && mat[i][j + 1] == 1) ? 1 : 0);
			}
			if (check(i + 1, j, n, m))
			{
				g[idx[{i, j}]].push_back(idx[{i + 1, j}]);
				wt[{idx[{i, j}], idx[{i + 1, j}]}] = ((mat[i][j] == 0 && mat[i + 1][j] == 1) ? 1 : 0);
			}
		}
	}
	return;
}

void sssp(int src, graph &g, v32 &dist, v32 &par, int inv)
{
	priority_queue<p32, vector<p32>, greater<p32>> Q;
	v32 visited(sz(dist), 0);
	dist[src] = 0;
	Q.push({0, src});
	par[src] = -1;
	while (!Q.empty())
	{
		auto itr = Q.top();
		Q.pop();
		int u = itr.se;
		int d = itr.fi;
		visited[u] = 1;
		for (auto v : g[u])
		{
			if (!visited[v] && dist[v] > abs(inv - wt[{u, v}]) + dist[u])
			{
				par[v] = u;
				dist[v] = abs(inv - wt[{u, v}]) + dist[u];
				Q.push({dist[v], v});
			}
		}
	}
	return;
}

int getAns(v32 &par, int n, int m, vector<v32> &mat)
{

	v32 path;
	int curr = idx[{n, m}];
	while (curr != -1)
	{
		path.push_back(curr);
		curr = par[curr];
	}
	reverse(path.begin(), path.end());
	int ans = 0;
	for (int i = 0; i < sz(path); i++)
	{
		auto itr = inv_idx[path[i]];
		int x = itr.fi, y = itr.se;
		if (mat[x][y] == 0)
			continue;
		int j = i;
		while (j < sz(path) && mat[inv_idx[path[j]].fi][inv_idx[path[j]].se] == 1)
			j++;
		ans++;
		i = j;
	}
	return ans;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<v32> mat(n + 1, v32(m + 1, 0));
	for (int i = 1; i < n + 1; i++)
	{
		string s;
		cin >> s;
		for (int j = 1; j < m + 1; j++)
			mat[i][j] = (s[j - 1] == '#' ? 1 : 0);
	}
	graph g(n * m + 1, v32());
	construct_graph(mat, g);
	v32 dist(n * m + 1, 1e9), par(n * m + 1, -1);
	sssp(idx[{1, 1}], g, dist, par, 0);
	int ans = getAns(par, n, m, mat);
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3456