#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main(int argc, char**argv) {
  int x, y, xi, yi, out;
  int xh = 0, yh = 0;
  char str[101][101];
  cin >> y >> x;
  while (x+y) {
    out = 0;
    for (xi = 0;xi < 101;xi++) {
      for (yi = 0;yi < 101;yi++) {
        if (xi < y && yi < x) cin >>  str[xi][yi];
        else str[xi][yi] = 0;
      }
    }
    for (xi = 0;xi < y;xi++) {
      for (yi = 0;yi < x;yi++) {
        if (!(xi != 0 && str[xi][yi] == str[xi-1][yi]) && !(yi != 0 && str[xi][yi] == str[xi][yi-1])) {
          out++;
          // printf("[ %d%d\n", xi, yi);
        } else if (xi != 0 && yi != 0 && str[xi][yi] == str[xi-1][yi] && str[xi][yi] == str[xi][yi-1] && str[xi-1][yi-1] != str[xi][yi-1]) {
          xh = xi, yh = yi-1;
          if (str[xh-1][yh] != str[xh][yh]) {
            out--;
            // printf("< %d%d by %d%d\n", xh, yh, xi, yi);
          }
        }
      }
    }
    cout << out << endl;
    cin >> y >> x;
  }
  return 0;
}