#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  char p;
  cin >> r >> c >> p;
  vector<string> room(r);
  for (int i = int(0); i < int(r); i++) cin >> room[i];
  set<char> s;
  for (int i = int(0); i < int(r); i++)
    for (int j = int(0); j < int(c); j++)
      if (room[i][j] == p) {
        int di[] = {-1, 1, 0, 0};
        int dj[] = {0, 0, -1, 1};
        for (int k = int(0); k < int(4); k++) {
          int ni = i + di[k];
          int nj = j + dj[k];
          if (ni < 0 || r <= ni || nj < 0 || c <= nj) continue;
          if (room[ni][nj] == '.' || room[ni][nj] == p) continue;
          s.insert(room[ni][nj]);
        }
      }
  cout << s.size() << endl;
  return 0;
}
