#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans(0);
  vector<vector<char> > matrx;
  map<char, int> rela;
  char c, ci;
  std::cin >> n >> m >> c;
  for (int i = 0; i < n; ++i) {
    vector<char> meh;
    for (int j = 0; j < m; ++j) {
      cin >> ci;
      meh.push_back(ci);
    }
    matrx.push_back(meh);
  }
  rela[c];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (matrx[i][j] == c) {
        if (i != 0 && matrx[i - 1][j] != '.' &&
            rela.count(matrx[i - 1][j]) == 0)
          ans++, rela[matrx[i - 1][j]];
        if (j != 0 && matrx[i][j - 1] != '.' &&
            rela.count(matrx[i][j - 1]) == 0)
          ans++, rela[matrx[i][j - 1]];
        if (j != m - 1 && matrx[i][j + 1] != '.' &&
            rela.count(matrx[i][j + 1]) == 0)
          ans++, rela[matrx[i][j + 1]];
        if (i != n - 1 && matrx[i + 1][j] != '.' &&
            rela.count(matrx[i + 1][j]) == 0)
          ans++, rela[matrx[i + 1][j]];
      }
    }
  cout << ans << endl;
  return 0;
}
