#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char c, ch;
  cin >> c;
  vector<vector<char> > v;
  for (int i = 0; i < n; i++) {
    std::vector<char> row;
    for (int j = 0; j < m; j++) {
      cin >> ch;
      row.push_back(ch);
    }
    v.push_back(row);
  }
  set<char> mset;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == c) {
        if (i != 0 && v[i - 1][j] != c && v[i - 1][j] != '.')
          mset.insert(v[i - 1][j]);
        if (j != 0 && v[i][j - 1] != c && v[i][j - 1] != '.')
          mset.insert(v[i][j - 1]);
        if (i != n - 1 && v[i + 1][j] != c && v[i + 1][j] != '.')
          mset.insert(v[i + 1][j]);
        if (j != m - 1 && v[i][j + 1] != c && v[i][j + 1] != '.')
          mset.insert(v[i][j + 1]);
      }
    }
  }
  cout << mset.size() << "\n";
  return 0;
}
