#include <bits/stdc++.h>
using namespace std;
char s[105][105];
int wb[105][105] = {};
int main() {
  int n, m, i, j, ans = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  for (i = n - 1; i >= 0; i--)
    for (j = m - 1; j >= 0; j--) {
      int sum = wb[i + 1][j] + wb[i][j + 1] - wb[i + 1][j + 1];
      if ((s[i][j] == 'B' ? 1 : -1) == sum)
        wb[i][j] = sum;
      else {
        ans++;
        wb[i][j] = (s[i][j] == 'B' ? 1 : -1);
      }
    }
  printf("%d\n", ans);
}
