#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int main(int, char**) {
  ios_base::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    vector<long long> c(m, 0);
    int ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      long long r = 0;
      for (int j = m - 1; j >= 0; --j) {
        long long v = a[i][j] == 'B' ? -1 : 1;
        c[j] += r;
        if (c[j] != v) {
          long long x = v - c[j];
          c[j] += x;
          r += x;
          ++ans;
        }
      }
    }
    cout << ans << endl;
  }
  fprintf(stderr, "Time execute: %.3lf sec\n",
          clock() / (double)CLOCKS_PER_SEC);
  return 0;
}
