#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;

int h,w,t[11][11],cnt[11],tmp[11][11];
int ans;

void solve()
{
	for(int i=1;i<=10;i++) cnt[i] = 0;
	for(int i=2;i<=h;i++) 
	{
		for(int j=2;j<=w;j++) 
		{
			if(t[i][j] != t[i-1][j]) cnt[j] = 1;
			else cnt[j] = 0;
		}
		int last = 0;
		for(int i=1;i<=w;i++) 
		{
			if(last == 0 && cnt[i] == 1) ans++;
			last = cnt[i];
		}
	}
}

int main()
{
	scanf("%d%d", &h, &w);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++) 
		{
			char c;
			cin >> c;
			if(c == '#') t[i][j] = 1;
		}
	}
	solve();
	//  cout << ans << "\n";
	for(int i=1;i<=h;i++) 
	{
		for(int j=1;j<=w;j++) 
		{
			tmp[j][i] = t[i][j];
		}
	}
	swap(h,w);
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) t[i][j] = tmp[i][j];
	solve();
	cout << ans << "\n";
	return 0;
}

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

struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
constexpr char newl = '\n';
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}
#if _local
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){std::cerr<<elm<<std::flush;return*this;}}dout;
#else
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){return*this;}}dout;
#endif

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  cin >> s;
  int ans = 0;
  bool prv = false;
  rep(i, h - 1) rep(j, w) {
    if (s[i][j] != s[i + 1][j]) {
      dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
           << prv << " " << ans << newl;
      ;
      if (!prv) {
        prv = true;
        ans++;
      }
    } else {
      prv = false;
    }
  }
  prv = false;
  rep(j, w - 1) rep(i, h) {
    if (s[i][j] != s[i][j + 1] ) {
      dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
           << prv << " " << ans << newl;
      if (!prv) {
        prv = true;
        ans++;
      }
    } else {
      prv = false;
    }
  }
  cout << (ans) << endl;
}
