#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      a[i][j] = (c == 'B');
    }
  int ans = 1;
  for (int i = 0; i < n - 1; ++i)
    for (int j = 0; j < m - 1; ++j) {
      int x = a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1];
      if (x == 3 || x == 1) ans++;
      if (a[i + 1][j + 1] == a[i][j] && a[i + 1][j] == a[i][j + 1] &&
          a[i][j] != a[i + 1][j])
        ans++;
    }
  for (int i = 0; i < n - 1; ++i)
    if (a[i][m - 1] != a[i + 1][m - 1]) ans++;
  for (int i = 0; i < m - 1; ++i)
    if (a[n - 1][i] != a[n - 1][i + 1]) ans++;
  cout << ans;
  return 0;
}
