#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int ans;
int anss[1000][1000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (c == 'B') {
        a[i][j] = -1;
      } else {
        a[i][j] = 1;
      }
    }
  }
  for (int d = m; d >= 1; --d) {
    int ii = max(n - (m - d), 1);
    int jj = d;
    for (int i = ii; i >= 1; --i) {
      if (a[i][jj] != anss[i][jj]) {
        ++ans;
        int cur = a[i][jj] - anss[i][jj];
        for (int iii = 1; iii <= i; ++iii) {
          for (int jjj = 1; jjj <= jj; ++jjj) {
            anss[iii][jjj] += cur;
          }
        }
      }
    }
    for (int j = jj - 1; j >= 1; --j) {
      if (a[ii][j] != anss[ii][j]) {
        ++ans;
        int cur = a[ii][j] - anss[ii][j];
        for (int iii = 1; iii <= ii; ++iii) {
          for (int jjj = 1; jjj <= j; ++jjj) {
            anss[iii][jjj] += cur;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
