#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
typedef vector<int> veci;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define foreach(i, n) for (typeof(n) i = 0; i < (n); ++i)
#define foreach_eq(i, n) for (typeof(n) i = 0; i <= (n); ++i)
#define foreach_from(i, m, n) for (typeof(n) i = m; i < (n); ++i)
#define foreach_eq_from(i, m, n) for (typeof(n) i = m; i <= (n); ++i)

int dirctions[4][2] = {{0,-1}, {0,1}, {-1,0}, {1,0}};

#define MAX_H 100
#define MAX_W 100

int H, W;
char data[MAX_H][MAX_W];
stack<pii> stk;

int main() {
    cin >> H >> W;
    foreach (i, H) foreach (j, W) cin >> data[i][j];

    int cnt = 0;
    foreach (i, H) {
        foreach (j, W) {
            char self = data[i][j];
            if (not self) continue;
            ++ cnt;
            stk.push(pii(i,j));
            while (not stk.empty()) {
                pii pos = stk.top();
                stk.pop();
                foreach (d, 4) {
                    pii nxt = pii(pos.first + dirctions[d][0], pos.second + dirctions[d][1]);
                    if (nxt.first < 0 || H <= nxt.first || nxt.second < 0 || W <= nxt.second) continue;
                    if (data[nxt.first][nxt.second] != self) continue;
                    data[nxt.first][nxt.second] = 0;
                    stk.push(nxt);
                }
            }
        }
    }

    cout << cnt << endl;
}