#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
using namespace std;
vector<string> v;
vector<vector<int> > d;
int print(int i, int j, int n, int m) {
  if (i == n || j == m) return 0;
  int s = v[n - 1][m - 1] - d[n - 1][m - 1];
  if (s == 0) return 0;
  for (int ii = i; ii < n; ii++) {
    for (int jj = j; jj < m; jj++) d[ii][jj] += s;
  }
  return 1;
}
int get(int i, int j, int n, int m) {
  if (i == n || j == m) return 0;
  int r = 0;
  r += print(0, 0, n, m);
  int k;
  for (k = m - 1; k >= j && d[n - 1][k] == v[n - 1][k]; k--) {
  }
  int l;
  for (l = n - 2; l >= i; l--) {
    bool bad = false;
    for (int s = m - 1; s > k && s >= j; s--) {
      if (d[l][s] != v[l][s]) {
        bad = true;
        break;
      }
    }
    if (bad) break;
  }
  r += get(l + 1, j, n, k + 1);
  r += get(i, k + 1, l + 1, m);
  r += get(i, j, l + 1, k + 1);
  return r;
}
int main() {
  int n, m;
  cin >> n >> m;
  v.resize(n);
  d.resize(n, vector<int>(m, -1));
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  char zero = v[n - 1][m - 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == zero)
        v[i][j] = 0;
      else
        v[i][j] = 1;
    }
  }
  cout << get(0, 0, n, m);
  return 0;
}
