#include <bits/stdc++.h>
using namespace std;
int main() {
  set<char> deputi;
  vector<vector<char> > off;
  int m, n;
  char boss;
  cin >> n >> m >> boss;
  off.resize(n);
  for (int i = 0; i < n; i++) off[i].resize(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) do {
        cin >> off[i][j];
      } while (off[i][j] == '\n');
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (off[i][j] == boss) {
        if (i > 0) deputi.insert(off[i - 1][j]);
        if (i < n - 1) deputi.insert(off[i + 1][j]);
        if (j > 0) deputi.insert(off[i][j - 1]);
        if (j < m - 1) deputi.insert(off[i][j + 1]);
      }
  deputi.erase('.');
  deputi.erase(boss);
  cout << deputi.size() << endl;
}
