#include <bits/stdc++.h>
using namespace std;
bool isOk(char c, int v) { return v == (c == 'B' ? -1 : 1); }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  string a[n];
  int v[n][m];
  char ch;
  int vx;
  int nOp = 0;
  for (int i = 0; i < n; i++) {
    fill(v[i], v[i] + m, 0);
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--) {
      if (!isOk(a[i][j], v[i][j])) {
        ++nOp;
        vx = (a[i][j] == 'W' ? v[i][j] - 1 : v[i][j] + 1);
        for (int i1 = 0; i1 <= i; i1++)
          for (int j1 = 0; j1 <= j; j1++) v[i1][j1] -= vx;
      }
    }
  printf("%d\n", nOp);
  return 0;
  return 0;
}
