#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  char a[n][m], s;
  cin >> s;
  vector<char> v;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == s) {
        if (a[i + 1][j] != '.' && a[i + 1][j] != s && i + 1 < n)
          v.push_back(a[i + 1][j]);
        if (a[i][j + 1] != '.' && a[i][j + 1] != s && j + 1 < m)
          v.push_back(a[i][j + 1]);
        if (a[i - 1][j] != '.' && a[i - 1][j] != s && i - 1 >= 0)
          v.push_back(a[i - 1][j]);
        if (a[i][j - 1] != '.' && a[i][j - 1] != s && j - 1 >= 0)
          v.push_back(a[i][j - 1]);
      }
    }
  }
  sort(v.begin(), v.end());
  if (v.size() == 0) {
    cout << "0";
    return 0;
  }
  long long c = 1;
  for (long long i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1] && 64 < v[i] && v[i] < 91) c++;
  }
  cout << c;
}
