#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];
    
    const int dy[] = {0, 1};
    const int dx[] = {1, 0};

    deque<int> qy, qx;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    vector<vector<int>> prev_y(h, vector<int>(w, -1)), prev_x(h, vector<int>(w, -1));

    qy.push_front(0); qx.push_front(0);
    if (field[0][0] == '#') dist[0][0] = 1;
    else dist[0][0] = 0;
    prev_y[0][0] = 0; prev_x[0][0] = 0;
    while (!qy.empty()) {
        int y = qy.front(), x = qx.front();
        qy.pop_front(); qx.pop_front();
        for (int i = 0; i < 2; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if (dist[ny][nx] >= 0) continue;
            if (field[ny][nx] == '#') {
                if (field[y][x] == '#') {
                    dist[ny][nx] = dist[y][x];
                    qy.push_front(ny); qx.push_front(nx);
                } else {
                    dist[ny][nx] = dist [y][x] + 1;
                    qy.push_back(ny); qx.push_back(nx);
                }
            } else {
                if (field[y][x] == '#') {
                    dist[ny][nx] = dist [y][x] + 1;
                    qy.push_back(ny); qx.push_back(nx);
                } else {
                    dist[ny][nx] = dist [y][x];
                    qy.push_front(ny); qx.push_front(nx);
                }
            }
            prev_y[ny][nx] = y; prev_x[ny][nx] = x;
        }
    }

    // rep(y, h) rep(x, w) printf("%d%c", dist[y][x], x==w-1?'\n':' ');
    
    int ans = 0;
    int flag = 0;
    if (field[h-1][w-1] == '#') flag = 1;
    // 復元
    int y = h-1, x = w-1;
    while (y != 0 || x != 0) {
        // 前の頂点へ行く
        int px = prev_x[y][x];
        int py = prev_y[y][x];
        
        x = px, y = py;
        if (field[y][x] == '#') { 
            flag = 1;
        } else {
            if (flag) {
                flag = 0;
                ans++;
            }
        }
    }
    if (flag) ans++;
    cout << ans << endl;

    // vector<int> path_y(200), path_x(200);
    // int cur_y = h-1, cur_x = w-1;
    // int idx;
    // while (cur_y != 0 || cur_x != 0) { 
    //     if (cur_y == 0) {
    //         path_y[idx] = 0;
    //         path_x[idx] = 1;
    //         cur_x--;
    //     } else if (cur_x == 0) {
    //         path_y[idx] = 1;
    //         path_x[idx] = 0;
    //         cur_y--;
    //     } else if (dist[cur_y-1][cur_x] <= dist[cur_y][cur_x-1]) {
    //         path_y[idx] = 1;
    //         path_x[idx] = 0;
    //         cur_y--;
    //     } else {
    //         path_y[idx] = 0;
    //         path_x[idx] = 1;
    //         cur_x--;
    //     }
    //     idx++;
    // }

    // rep(i, idx) {
    //     cur_y += path_y[i];
    //     cur_x += path_x[i];
    //     if (field[cur_y][cur_x] == '#') { 
    //         flag = 1;
    //     } else {
    //         if (flag) {
    //             flag = 0;
    //             ans++;
    //         }
    //     }
    // }
    // if (flag) ans++;
    // cout << ans << endl;
}

Measured memory_bytes: 384