#include <bits/stdc++.h>
using namespace std;
bool table[26] = {};
int main(void) {
  int n, m;
  string s[106];
  char c;
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == c) {
        if (i != 0 && s[i - 1][j] != '.') table[s[i - 1][j] - 'A'] = true;
        if (j != 0 && s[i][j - 1] != '.') table[s[i][j - 1] - 'A'] = true;
        if (i != n - 1 && s[i + 1][j] != '.') table[s[i + 1][j] - 'A'] = true;
        if (j != m - 1 && s[i][j + 1] != '.') table[s[i][j + 1] - 'A'] = true;
      }
    }
  }
  table[c - 'A'] = false;
  int ans = 0;
  for (int i = 0; i < 26; i++)
    if (table[i]) ans++;
  cout << ans << endl;
  return 0;
}
