/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll n,m;
  cin>>n>>m;
  string s[n];
  rep(i,0,n) cin>>s[i];
  ll ans[n+1][m+1]={0};
  rep(i,0,n+1) rep(j,0,m+1) ans[i][j]=hell;
  ll vis[n+1][m+1];
  rep(i,0,n+1) rep(j,0,m+1) vis[i][j]=0;
  if(s[0][0]=='#') {
    vis[0][0]=1;
    ans[0][0]=1;
    queue <pii> q;
    q.push({0,0});
    pii p;
    ll x,y;
    while(!q.empty())
    {
      p=q.front();
      q.pop();
      if(((p.F+1)<n)&&(s[p.F+1][p.S]=='#')&&(!vis[p.F+1][p.S]))
      {
        q.push({p.F+1,p.S});
        vis[p.F+1][p.S]=1;
        x=p.F+1;
        y=p.S;
        ans[x][y]=1;
      }
      if((p.S+1<m)&&(s[p.F][p.S+1]=='#')&&(!vis[p.F][p.S+1]))
      {
        q.push({p.F,p.S+1});
        vis[p.F][p.S+1]=1;
        x=p.F;
        y=p.S+1;
        ans[x][y]=1;
      }
    }
  }
  else ans[0][0]=0;
  rep(i,0,n) 
  rep(j,0,m)
  {
    if((i||j)&&(s[i][j]=='#'))
    {
      ll tmp=hell;
      if(i) tmp=min(tmp,ans[i-1][j]);
      if(j) tmp=min(tmp,ans[i][j-1]);
      ll vis[n][m];
      rep(k,0,n) rep(l,0,m) vis[k][l]=0;   
      vis[i][j]=1;
      ans[i][j]=min(ans[i][j],tmp+1);
      // if(i==1&&j==0) cout<<tmp<<endl,cout<<ans[i][j]<<endl;
      queue <pii> q;
      q.push({i,j});
      pii p;
      ll x,y;
      while(!q.empty())
      {
        p=q.front();
        q.pop();
        // cout<<p.F<<' '<<p.S<<endl;
        if((p.F+1<n)&&(s[p.F+1][p.S]=='#')&&(!vis[p.F+1][p.S]))
        {
          q.push({p.F+1,p.S});
          vis[p.F+1][p.S]=1;
          x=p.F+1;
          y=p.S;
          ans[x][y]=min(ans[x][y],tmp+1);
        }
        if((p.S+1<m)&&(s[p.F][p.S+1]=='#')&&(!vis[p.F][p.S+1]))
        {
          q.push({p.F,p.S+1});
          vis[p.F][p.S+1]=1;
          x=p.F;
          y=p.S+1;
          ans[x][y]=min(ans[x][y],tmp+1);
        }
      }
    }
    else if(i||j){
      ll tmp=hell;
      if(i) tmp=min(tmp,ans[i-1][j]);
      if(j) tmp=min(tmp,ans[i][j-1]);
      ans[i][j]=min(tmp,ans[i][j]);
    }
  }
  // rep(i,0,n) {
  //   rep(j,0,m) cout<<ans[i][j]<<' ';
  //   cout<<endl;
  // }
  cout<<ans[n-1][m-1]<<endl;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 512