#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  char pre;
  cin >> n >> m >> pre;
  vector<string> P(n);
  for (int i = 0; i < n; ++i) cin >> P[i];
  vector<bool> biu(26, false);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (P[i][j] == pre) {
        if (i - 1 >= 0 && P[i - 1][j] != '.' && P[i - 1][j] != pre)
          biu[P[i - 1][j] - 'A'] = true;
        if (i + 1 < n && P[i + 1][j] != '.' && P[i + 1][j] != pre)
          biu[P[i + 1][j] - 'A'] = true;
        if (j - 1 >= 0 && P[i][j - 1] != '.' && P[i][j - 1] != pre)
          biu[P[i][j - 1] - 'A'] = true;
        if (j + 1 < m && P[i][j + 1] != '.' && P[i][j + 1] != pre)
          biu[P[i][j + 1] - 'A'] = true;
      }
    }
  }
  int il = 0;
  for (int i = 0; i < 26; ++i)
    if (biu[i]) ++il;
  cout << il;
  return 0;
}
