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

int main() {
    int h, w;
    cin >> h >> w;
    int ans = 0;
    vector<bool> below(w),  above(w);
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            below[j] = (s[j] == '#');
        }
        if (i == 0) continue;
        for (int j = 0; j+1 < w; j++) {
            int cnt = below[j] + below[j+1] 
                + above[j] + above[j+1];
            if (cnt == 1 || cnt == 3)
                ans++;
        }
        above = below;
    }
    cout << ans << endl;
    return 0;
}
#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE 
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE 
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>
 
 
using namespace std;
#ifdef ONLINE_JUDGE 
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE 
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
 
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);
 
  ll X,Y; cin>>X>>Y;
  if(X>=Y) {
    cout<<abs(X-Y)<<'\n';
    return 0;
  }
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  pq.push({0,Y});
  map<ll,ll> dp;
  ll ans=INF;
  while(!pq.empty()) {
    auto [c,v]=pq.top(); pq.pop();
    chmin(ans,c+abs(v-X));
    if(dp.count(v)) continue;
    dp[v]=c;
    if(v<X) continue;
    if(v==X) break;
    if(~v&1) pq.push({c+1,v/2});
    else {
      pq.push({c+1,v+1});
      pq.push({c+1,v-1});
    }
    pq.push({c+abs(v-X),X});
  }
  
  cout<<ans<<'\n';
  
  return 0;
}