#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, sum = 0;
  cin >> n >> m;
  vector<vector<int> > square(n, vector<int>(m));
  vector<vector<int> > ans(n, vector<int>(m));
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 0; j <= m - 1; ++j) ans[i][j] = 0;
  }
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 0; j <= m - 1; ++j) {
      char ch;
      cin >> ch;
      if (ch == 'W')
        square[i][j] = 1;
      else
        square[i][j] = -1;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if (ans[i][j] != square[i][j]) {
        int temp = square[i][j] - ans[i][j];
        for (int k = 0; k <= i; ++k) {
          for (int l = 0; l <= j; ++l) {
            ans[k][l] += temp;
          }
        }
        ++sum;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
