#include <bits/stdc++.h>
using namespace std;
const int NSIZE = 100 + 10;
string fo[NSIZE];
int i, N, M, ans, j;
int p[NSIZE][NSIZE];
int main() {
  cin >> N >> M;
  for (i = 0; i < N; ++i) cin >> fo[i];
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j) p[i][j] = (fo[i][j] == 'B') ? 1 : -1;
  for (i = 0; i < N; ++i)
    for (j = 0; j < M - 1; ++j) p[i][j] -= p[i][j + 1];
  for (i = 0; i < N - 1; ++i)
    for (j = 0; j < M; ++j) p[i][j] -= p[i + 1][j];
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j) ans += (!p[i][j]);
  cout << N * M - ans << '\n';
  return 0;
}
