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

auto wall = 'w';
char black = '#';
//=============dfs============================
int dfs(vector<vector<char>> maze, pair<int, int> start, pair<int, int> end)
{
  queue<tuple<int, int, int, bool>> q;
  vector<vector<int>> ans(maze.size(), vector<int>(maze.at(0).size(), INF));
  tuple<int, int, int, bool> temp;// get<3> last == #
  get<0>(temp) = start.first;get<1>(temp) = start.second;get<2>(temp) = 0;
  get<3>(temp) = false;
  ans.at(1).at(1) = 0;
  if (maze.at(start.first).at(start.second) == '#')
  {
    get<2>(temp) += 1;
    ans.at(1).at(1) += 1;
    get<3>(temp) = true;
  }
  q.push(temp);
  while (!q.empty())
  {
    // cout << "in" << endl;
    tuple<int, int, int, bool> check = q.front();
    q.pop();
    // if (ans.at(get<0>(check)).at(get<1>(check)) <= get<2>(check))
    // {
    //   continue;
    // }
    // ans.at(get<0>(check)).at(get<1>(check)) = get<2>(check);

    // if (get<0>(check) == end.first && get<1>(check) == end.second)
    // {
    //   for (int i = 0; i < maze.size(); ++i)
    //   {
    //     for (int j = 0; j < maze.at(0).size(); ++j)
    //     {
    //       cout << ans.at(i).at(j) << ' ';
    //     }
    //     cout << endl;
    //   }
    //   return get<2>(check);
    // }

    if (maze.at(get<0>(check) + 1).at(get<1>(check)) != wall)
    {
      if (maze.at(get<0>(check) + 1).at(get<1>(check)) == black)
      {
        get<0>(temp) = get<0>(check) + 1;get<1>(temp) = get<1>(check);get<2>(temp) = get<2>(check);
        if (!get<3>(check))
        {
          get<2>(temp) += 1;
        }
        get<3>(temp) = true;
      }
      else
      {
        get<0>(temp) = get<0>(check) + 1;get<1>(temp) = get<1>(check);get<2>(temp) = get<2>(check);
        get<3>(temp) = false;
      }
      if (get<2>(temp) < ans.at(get<0>(temp)).at(get<1>(temp)))
      {
        q.push(temp);
        ans.at(get<0>(temp)).at(get<1>(temp)) = get<2>(temp);
      }
    }
    if (maze.at(get<0>(check)).at(get<1>(check) + 1) != wall)
    {
      if (maze.at(get<0>(check)).at(get<1>(check) + 1) == black)
      {
        get<0>(temp) = get<0>(check);get<1>(temp) = get<1>(check) + 1;get<2>(temp) = get<2>(check);
        if (!get<3>(check))
        {
          get<2>(temp) += 1;
        }
        get<3>(temp) = true;
      }
      else
      {
        get<0>(temp) = get<0>(check);get<1>(temp) = get<1>(check) + 1;get<2>(temp) = get<2>(check);
        get<3>(temp) = false;
      }
      if (get<2>(temp) < ans.at(get<0>(temp)).at(get<1>(temp)))
      {
        q.push(temp);
        ans.at(get<0>(temp)).at(get<1>(temp)) = get<2>(temp);
      }
    }
    // if (maze.at(get<0>(check) - 1).at(get<1>(check)) != wall)
    // {
    //   if (maze.at(get<0>(check) - 1).at(get<1>(check)) == black)
    //   {
    //     get<0>(temp) = get<0>(check) - 1;get<1>(temp) = get<1>(check);get<2>(temp) = get<2>(check) + 1;
    //   }
    //   else
    //   {
    //     get<0>(temp) = get<0>(check) - 1;get<1>(temp) = get<1>(check);get<2>(temp) = get<2>(check);
    //   }
    //   q.push(temp);
    // }
    // if (maze.at(get<0>(check)).at(get<1>(check) - 1) != wall)
    // {
    //   if (maze.at(get<0>(check)).at(get<1>(check) - 1) == black)
    //   {
    //     get<0>(temp) = get<0>(check);get<1>(temp) = get<1>(check) - 1;get<2>(temp) = get<2>(check) + 1;
    //   }
    //   else
    //   {
    //     get<0>(temp) = get<0>(check);get<1>(temp) = get<1>(check) - 1;get<2>(temp) = get<2>(check);
    //   }
    //   if (get<2>(temp) < ans.at(get<0>(temp)).at(get<1>(temp)))
    //   {
    //     q.push(temp);
    //     ans.at(get<0>(temp)).at(get<1>(temp)) = get<2>(temp);
    //   }
    // }
  }
  // for (int i = 0; i < maze.size(); ++i)
  // {
  //   for (int j = 0; j < maze.at(0).size(); ++j)
  //   {
  //     cout << ans.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
  return ans.at(end.first).at(end.second);
}
//=================================================

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H + 2, vector<char>(W + 2, 'w'));
  for (int i = 1; i < H + 1; ++i)
  {
    for (int j = 1; j < W + 1; ++j)
    {
      cin >> maze.at(i).at(j);
    }
  }
  int ans = dfs(maze, {1, 1}, {H, W});
  cout << ans << endl;
}


Measured memory_bytes: 384