#include<bits/stdc++.h>
using namespace std;
void setup(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
set<char> st;
int h,w;
bool check(const vector<string> &s,vector<vector<bool>> &vis,int i,int j){
return (i >= 0 && i < h && j >= 0 && j < w && s[i][j] != '.' && !vis[i][j]);
}
void dfs(const vector<string> &s,vector<vector<bool>> &vis,int i,int j){
vis[i][j] = 1;
st.insert(s[i][j]);
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
for(int k = 0;k < 4;k++){
if(check(s,vis,i+dy[k],j+dx[k])){
dfs(s,vis,i+dy[k],j+dx[k]);
}
}
}
int main(){
setup();
cin >> h >> w;
vector<string> s(h);
vector<vector<bool>> vis(h,vector<bool> (w,0));
for(auto &i : s)cin >> i;
dfs(s,vis,0,0);
cout << st.size();
}