#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = (int)1e9;
const double inf1 = 1e-9;
const int ss = (int)1e6 + 3;
bool myf(const pair<int, int>& i, const pair<int, int>& j) {
  return (i.first < j.first);
}
int a[4] = {-1, 0, 1, 0};
int b[4] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  char z;
  cin.get();
  cin.get(z);
  cin.get();
  vector<string> res(n);
  set<char> out;
  vector<pair<int, int> > mas;
  for (int i = 0; i < n; ++i) {
    getline(cin, res[i]);
    for (int j = 0; j < m; ++j)
      if (res[i][j] == z) mas.push_back(make_pair(i, j));
  }
  for (int i = 0; i < mas.size(); ++i) {
    for (int j = 0; j < 4; ++j) {
      int x = mas[i].first + a[j];
      int y = mas[i].second + b[j];
      if (x >= 0 && x < n && y >= 0 && y < m && res[x][y] != z &&
          res[x][y] != '.') {
        out.insert(res[x][y]);
      }
    }
  }
  cout << out.size();
  return 0;
}
