#include <bits/stdc++.h>
using namespace std;
string world[200];
int coef[200][200];
int main() {
  int n, m;
  cin >> n >> m;
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    cin >> world[i];
  }
  int ans = 0;
  while (1) {
    int cnt = 0;
    for (int(i) = (0); (i) < (int)(n); ++(i)) {
      for (int(j) = (0); (j) < (int)(m); ++(j)) {
        int second = n - 1 - i;
        int first = m - 1 - j;
        int add = 0;
        if (world[second][first] == 'W' && coef[second][first] != 1) {
          add = 1 - coef[second][first];
        } else if (world[second][first] == 'B' && coef[second][first] != -1) {
          add = -1 - coef[second][first];
        }
        if (add != 0) {
          cnt++;
          for (int(ci) = (0); (ci) < (int)(second + 1); ++(ci)) {
            for (int(cj) = (0); (cj) < (int)(first + 1); ++(cj)) {
              coef[ci][cj] += add;
            }
          }
        }
        if (cnt) break;
      }
      if (cnt) break;
    }
    if (cnt) {
      ans++;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
