#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  char ch;
  set<char> s;
  vector<pair<int, int>> v;
  char arr[110][110];
  cin >> n >> m >> ch;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
      if (arr[i][j] == ch) v.push_back(make_pair(i, j));
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    if (arr[v[i].first][v[i].second - 1] != '.' &&
        arr[v[i].first][v[i].second - 1] != ch && (v[i].second - 1) >= 0)
      s.insert(arr[v[i].first][v[i].second - 1]);
    if (arr[v[i].first][v[i].second + 1] != '.' &&
        arr[v[i].first][v[i].second + 1] != ch && (v[i].second + 1) < m)
      s.insert(arr[v[i].first][v[i].second + 1]);
    if (arr[v[i].first + 1][v[i].second] != '.' &&
        arr[v[i].first + 1][v[i].second] != ch && (v[i].first + 1) < n)
      s.insert(arr[v[i].first + 1][v[i].second]);
    if (arr[v[i].first - 1][v[i].second] != '.' &&
        arr[v[i].first - 1][v[i].second] != ch && (v[i].first - 1) >= 0)
      s.insert(arr[v[i].first - 1][v[i].second]);
  }
  cout << s.size() << endl;
  return 0;
}
