#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int r = 0;
  vector<string> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int> > val(n, vector<int>(m, 0));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      int v = 0;
      if (j < m - 1) v += val[i][j + 1];
      if (i < n - 1) v += val[i + 1][j];
      if (i < n - 1 && j < m - 1) v -= val[i + 1][j + 1];
      if (a[i][j] == 'B') {
        if (v != -1) {
          r++;
        }
        val[i][j] = -1;
      } else {
        if (v != 1) {
          r++;
        }
        val[i][j] = 1;
      }
    }
  }
  cout << r << endl;
}
