#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char> > field(n, vector<char>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      do {
        cin >> field[i][j];
      } while (!('W' == field[i][j] || field[i][j] == 'B'));
    }
  }
  int ans = 0;
  vector<vector<int> > my_field(n, vector<int>(m));
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if ((field[i][j] == 'W' && my_field[i][j] != 1) ||
          (field[i][j] == 'B' && my_field[i][j] != -1)) {
        ++ans;
        auto d = (field[i][j] == 'W' ? 1 : -1) - my_field[i][j];
        for (int x = 0; x <= i; ++x) {
          for (int y = 0; y <= j; ++y) {
            my_field[x][y] += d;
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
