#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int mxN = 105;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int s[mxN][mxN], s1[mxN][mxN];
bool cmp(pair<int, int> a, pair<int, int> b) {
  return (a.first + a.second) < (b.first + b.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      char c;
      cin >> c;
      if (c == 'W')
        s[i][j] = s1[i][j] = 1;
      else
        s[i][j] = s1[i][j] = -1;
    }
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 function<bool(pair<int, int>, pair<int, int>)>>
      pq(cmp);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++)
      if (s[i][j] != 1) pq.push({i, j});
  int ans = 1e9;
  int cur = 1;
  while (pq.size()) {
    pair<int, int> cur1 = pq.top();
    pq.pop();
    if (s[cur1.first][cur1.second] != 1) {
      int dif = 1 - s[cur1.first][cur1.second];
      for (int i = 0; i < (int)(cur1.first + 1); i++)
        for (int j = 0; j < (int)(cur1.second + 1); j++) {
          if (s[i][j] == 1) pq.push({i, j});
          s[i][j] += dif;
        }
      cur++;
    }
  }
  swap(s, s1);
  ans = min(ans, cur);
  while (pq.size()) pq.pop();
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++)
      if (s[i][j] != -1) pq.push({i, j});
  cur = 1;
  while (pq.size()) {
    pair<int, int> cur1 = pq.top();
    pq.pop();
    if (s[cur1.first][cur1.second] != -1) {
      int dif = -1 - s[cur1.first][cur1.second];
      for (int i = 0; i < (int)(cur1.first + 1); i++)
        for (int j = 0; j < (int)(cur1.second + 1); j++) {
          if (s[i][j] == -1) pq.push({i, j});
          s[i][j] += dif;
        }
      cur++;
    }
  }
  ans = min(ans, cur);
  cout << ans << endl;
  return 0;
}
