#include <bits/stdc++.h>
using namespace std;
int n, m;
int getVal(vector<std::vector<int> > ans, vector<vector<int> > val) {
  int sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (ans[i][j] == val[i][j])
        continue;
      else {
        int diff = val[i][j] - ans[i][j];
        sum++;
        for (int k = 0; k <= i; k++) {
          for (int l = 0; l <= j; l++) {
            ans[k][l] = ans[k][l] + diff;
          }
        }
      }
    }
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  vector<vector<int> > a;
  for (int i = 0; i < n; i++) {
    a.push_back(vector<int>());
    for (int j = 0; j < m; j++) {
      char val;
      cin >> val;
      if (val == 'W')
        a[i].push_back(1);
      else
        a[i].push_back(-1);
    }
  }
  vector<vector<int> > ans;
  for (int i = 0; i < n; i++) {
    ans.push_back(vector<int>());
    for (int j = 0; j < m; j++) {
      ans[i].push_back(1);
    }
  }
  int val = getVal(ans, a);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans[i][j] = -1;
    }
  }
  val = min(val, getVal(ans, a));
  cout << val + 1 << endl;
  return 0;
}
