#include <bits/stdc++.h>
using namespace std;
struct node {
  int i;
  int j;
  int dist;
};
vector<node> store;
bool comp(const struct node &t1, const struct node &t2) {
  return t1.dist > t2.dist;
}
int main() {
  int n, m;
  int i, j;
  cin >> n >> m;
  string str[n];
  node temp;
  for (i = 0; i < n; i++) {
    cin >> str[i];
    for (j = 0; j < m; j++) {
      temp.i = i;
      temp.j = j;
      temp.dist = i + j;
      store.push_back(temp);
    }
  }
  sort(store.begin(), store.end(), comp);
  int arr[n][m];
  int count1 = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) arr[i][j] = 0;
  int t;
  int is;
  int js;
  int val;
  for (t = 0; t < store.size(); t++) {
    is = store[t].i;
    js = store[t].j;
    if ((str[is][js] == 'W' && arr[is][js] == 1) ||
        (str[is][js] == 'B' && arr[is][js] == -1))
      continue;
    else {
      if (str[is][js] == 'W') {
        val = 1 - arr[is][js];
      } else if (str[is][js] == 'B') {
        val = -1 - arr[is][js];
      }
      for (i = 0; i <= is; i++) {
        for (j = 0; j <= js; j++) {
          arr[i][j] += val;
        }
      }
      count1++;
    }
  }
  cout << count1 << "\n";
  return 0;
}
