#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int h, w;
    cin >> h >> w;
    std::vector<std::vector<int>> Map(h, std::vector<int>(w));
    for (int i = 0; i < h; i++) {
        std::string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') {
                Map[i][j] = 1;
            } else {
                Map[i][j] = 0;
            }
        }
    }
    std::vector<std::vector<int>> out(h, std::vector<int>(w, MOD));

    std::queue<pii> qu;
    qu.push({0, 0});
    if (Map[0][0] == 1) {
        out[0][0] = 1;
    } else {
        out[0][0] = 0;
    }
    while (!qu.empty()) {
        pii now = qu.front();
        qu.pop();
        int f = now.first;
        int s = now.second;
        if (f + 1 < h) {
            if (Map[f][s] == Map[f + 1][s] || Map[f + 1][s] == 0) {
                if (out[f + 1][s] > out[f][s]) {
                    chmin(out[f + 1][s], out[f][s]);
                    qu.push({f + 1, s});
                }
            } else {
                if (out[f + 1][s] > out[f][s] + 1) {
                    chmin(out[f + 1][s], out[f][s] + 1);
                    qu.push({f + 1, s});
                }
            }
        }
        if (s + 1 < w) {
            if (Map[f][s] == Map[f][s + 1] || Map[f][s + 1] == 0) {
                if (out[f][s + 1] > out[f][s]) {
                    chmin(out[f][s + 1], out[f][s]);
                    qu.push({f, s + 1});
                }
            } else {
                if (out[f][s + 1] > out[f][s] + 1) {
                    chmin(out[f][s + 1], out[f][s] + 1);
                    qu.push({f, s + 1});
                }
            }
        }
    }
    cout << out[h - 1][w - 1] << endl;
    return 0;
}

Measured memory_bytes: 384