#include <bits/stdc++.h>
using namespace std;
long long n, m, z, x, c, sum, a[101][101], us[101][101];
char cc, stl;
set<long long> s;
void dfs(long long i, long long j) {
  if (a[i][j] == 0 || us[i][j] == 1 || i > n || j > m || i < 1 || j < 1) return;
  us[i][j] = 1;
  if (s.count(a[i][j]) == 0) sum++, s.insert(a[i][j]);
  if (a[i][j] == stl - 'A' + 1) {
    dfs(i + 1, j);
    dfs(i - 1, j);
    dfs(i, j + 1);
    dfs(i, j - 1);
  }
}
int main() {
  cin >> n >> m >> stl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> cc;
      if (cc != '.') a[i][j] = cc - 'A' + 1;
      if (cc == stl) z = i, x = j;
    }
  }
  s.insert((int)stl - 'A' + 1);
  dfs(z, x);
  cout << sum << "\n";
}
