#include <bits/stdc++.h>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    string S[H];
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }
    int dp[H][W];
    int dplast[H][W];
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            dp[i][j] = 0;
            dplast[i][j] = 0;
        }
        
    }
     
    if (S[0][0] == '#')
    {
        dp[0][0] = 1;
        dplast[0][0] = 1;
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (i == 0 && j == 0)
                continue;
            if (i > 0)
            {
                int dptmp = 10000;
                int dplasttmp = 0;
                if (dplast[i - 1][j] == 0)
                {
                    if (S[i][j] == '#')
                    {
                        dp[i][j] = dp[i - 1][j] + 1;
                        dplast[i][j] = 1;
                    }
                    else
                    {
                        dp[i][j] = dp[i - 1][j];
                        dplast[i][j] = 0;
                    }
                }
                else
                {
                    if (S[i][j] == '#')
                    {
                        dp[i][j] = dp[i - 1][j];
                        dplast[i][j] = 1;
                    }
                    else
                    {
                        dp[i][j] = dp[i - 1][j];
                        dplast[i][j] = 0;
                    }
                }
                if (j > 0)
                {
                    if (dplast[i][j - 1] == 0)
                    {
                        if (S[i][j] == '#')
                        {
                            dptmp = dp[i][j - 1] + 1;
                            dplasttmp = 1;
                        }
                        else
                        {
                            dptmp = dp[i][j - 1];
                            dplasttmp = 0;
                        }
                    }
                    else
                    {
                        if (S[i][j] == '#')
                        {
                            dptmp = dp[i][j - 1];
                            dplasttmp = 1;
                        }
                        else
                        {
                            dptmp = dp[i][j - 1];
                            dplasttmp = 0;
                        }
                    }
                }
                if (dp[i][j] > dptmp)
                {
                    dp[i][j] = dptmp;
                    dplast[i][j] = dplasttmp;
                }
            }
            else
            {
                if (dplast[i][j - 1] == 0)
                {
                    if (S[i][j] == '#')
                    {
                        dp[i][j] = dp[i][j - 1] + 1;
                        dplast[i][j] = 1;
                    }
                    else
                    {
                        dp[i][j] = dp[i][j - 1];
                        dplast[i][j] = 0;
                    }
                }
                else
                {
                    if (S[i][j] == '#')
                    {
                        dp[i][j] = dp[i][j - 1];
                        dplast[i][j] = 1;
                    }
                    else
                    {
                        dp[i][j] = dp[i][j - 1];
                        dplast[i][j] = 0;
                    }
                }
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 384