#include <bits/stdc++.h>
using namespace std;
int n, m;
void read(int &x) {
  char ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int ans;
char a[555][555];
int c[555][555], b[555][555];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == 'W')
        c[i][j] = 1;
      else
        c[i][j] = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) b[i][j] = 0;
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      if (b[i][j] != c[i][j]) {
        ans++;
        int delta = c[i][j] - b[i][j];
        for (int k = 1; k <= i; k++)
          for (int p = 1; p <= j; p++) b[k][p] += delta;
      }
    }
  printf("%d\n", ans);
}
