#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int flag[113][113];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int wall[113][113];
int wall2[113][113];
int use[113][113];
bool pain[113][113];
inline void dfs(int a, int b) {
  use[a][b] = true;
  for (int i = 0; i < 4; i++) {
    int aa = a + dx[i];
    int bb = b + dy[i];
    if (aa >= 0 && bb >= 0 && aa < n && bb < m) {
      if (use[aa][bb] == false) {
        if (a == aa) {
          if (wall[a][max(b, bb)]) {
            continue;
          }
        } else {
          if (wall2[max(a, aa)][b]) {
            continue;
          }
        }
        dfs(aa, bb);
      }
    }
  }
}
set<pair<int, int> > ss;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == 'B') {
        flag[i][j] = 1;
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    flag[i][m] = 2;
    wall[i][m] = 1;
  }
  for (int j = 0; j <= m; j++) {
    flag[n][j] = 2;
    wall2[n][j] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 4; k++) {
        int ii = i + dx[k];
        int jj = j + dy[k];
        if (ii >= 0 && jj >= 0 && ii < n && jj < m) {
          if (flag[i][j] != flag[ii][jj]) {
            if (i == ii) {
              for (int k = 0; k <= i; k++) {
                wall[k][max(j, jj)] = 1;
              }
            } else {
              for (int k = 0; k <= jj; k++) {
                wall2[max(i, ii)][k] = 1;
              }
            }
          }
        }
      }
    }
  }
  ss.clear();
  int countt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0) {
        continue;
      }
      if (i && j) {
        if (flag[i - 1][j] != flag[i][j] && flag[i - 1][j - 1] != flag[i][j] &&
            flag[i][j - 1] != flag[i][j]) {
          ss.insert(make_pair(i - 1, j - 1));
        }
      }
      bool ok = false;
      if (j) {
        if (flag[i][j] != flag[i][j - 1]) {
          if (flag[i + 1][j - 1] != flag[i][j] &&
              flag[i + 1][j] == flag[i][j]) {
            ok = true;
          } else {
            ss.insert(make_pair(i, j - 1));
          }
        } else {
          ok = true;
        }
      }
      if (i) {
        if (flag[i][j] != flag[i - 1][j] && flag[i][j + 1] != flag[i][j]) {
          ss.insert(make_pair(i - 1, j));
        } else {
          ok = true;
        }
      }
    }
  }
  countt = ss.size();
  printf("%d\n", countt + 1);
  return 0;
}
