#include <bits/stdc++.h>
using namespace std;
const int maxn = 150;
int N, M, son[maxn], ar[maxn][maxn], ans;
void upd(int a, int b, int c) {
  for (int i = 1; i <= a; i++)
    for (int j = 1; j <= b; j++) ar[i][j] += c;
  for (int i = N; i >= 1; i--)
    while (!ar[i][son[i]] && son[i] > son[i + 1]) son[i]--;
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      char a;
      scanf(" %c", &a);
      ar[i][j] = -1;
      if (a == 'B') ar[i][j] = 1;
    }
  for (int i = 1; i <= N; i++) son[i] = M;
  while (N) {
    upd(N, son[N], -ar[N][son[N]]);
    while (!son[N] && N) N--;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
