#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, h;
  cin >> n >> m;
  string prizn[n];
  for (i = 0; i < n; i++) cin >> prizn[i];
  int table[n][m];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) table[i][j] = 0;
  int value, mod;
  value = 0;
  for (i = n - 1; i >= 0; i--) {
    for (j = m - 1; j >= 0; j--) {
      if (prizn[i][j] == 'W')
        mod = 1 - table[i][j];
      else
        mod = -1 - table[i][j];
      if (mod != 0) {
        for (k = 0; k <= i; k++)
          for (h = 0; h <= j; h++) table[k][h] += mod;
        value++;
      }
    }
  }
  cout << value;
}
