#include <bits/stdc++.h>
using namespace std;
const int treeSize = 128;
int trees[100][treeSize * 2];
int get(int y, int x) {
  x += treeSize;
  int total = 0;
  while (x > 0) {
    total += trees[y][x];
    x /= 2;
  }
  return total;
}
void add(int y, int a, int b, int v) {
  a += treeSize;
  b += treeSize;
  int minv = INT_MAX;
  while (a <= b) {
    if (a % 2 == 1) {
      trees[y][a] += v;
      a++;
    }
    if (b % 2 == 0) {
      trees[y][b] += v;
      b--;
    }
    a /= 2;
    b /= 2;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> target(w, vector<int>(h));
  vector<vector<int>> value(w + 1, vector<int>(h + 1));
  vector<vector<int>> oper(w + 1, vector<int>(h + 1));
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      char c;
      cin >> c;
      if (c == 'B')
        target[x][y] = -1;
      else if (c == 'W')
        target[x][y] = 1;
    }
  int opera = 0;
  for (int y = h - 1; y >= 0; y--)
    for (int x = w - 1; x >= 0; x--) {
      int nowValue = get(y, x);
      int change = target[x][y] - nowValue;
      if (change != 0) {
        opera++;
        for (int y2 = 0; y2 <= y; y2++) add(y2, 0, x, change);
      }
    }
  cout << opera << endl;
  return 0;
}
