#include <iostream>
using namespace std;
int main() {
int w, h, res = 0;
cin >> w >> h;
char **x = new char *[h];
for (int i = 0; i < h; i++) x[i] = new char[w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> x[i][j];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w - 1; j++) {
if (x[i][j] != x[i][j + 1]) res++;
}
}
for (int i = 0; i < h - 1; i++) {
for (int j = 0; j < w; j++) {
if (x[i][j] != x[i + 1][j]) res++;
}
}
cout << res << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgdywgaCwgcmVzID0gMDsKCWNpbiA+PiB3ID4+IGg7CgljaGFyICoqeCA9IG5ldyBjaGFyICpbaF07Cglmb3IgKGludCBpID0gMDsgaSA8IGg7IGkrKykgeFtpXSA9IG5ldyBjaGFyW3ddOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBoOyBpKyspIHsKCQlmb3IgKGludCBqID0gMDsgaiA8IHc7IGorKykgewoJCQljaW4gPj4geFtpXVtqXTsKCQl9Cgl9Cglmb3IgKGludCBpID0gMDsgaSA8IGg7IGkrKykgewoJCWZvciAoaW50IGogPSAwOyBqIDwgdyAtIDE7IGorKykgewoJCQlpZiAoeFtpXVtqXSAhPSB4W2ldW2ogKyAxXSkgcmVzKys7CgkJfQoJfQoJZm9yIChpbnQgaSA9IDA7IGkgPCBoIC0gMTsgaSsrKSB7CgkJZm9yIChpbnQgaiA9IDA7IGogPCB3OyBqKyspIHsKCQkJaWYgKHhbaV1bal0gIT0geFtpICsgMV1bal0pIHJlcysrOwoJCX0KCX0KCWNvdXQgPDwgcmVzIDw8IGVuZGw7CglyZXR1cm4gMDsKfQ==