#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[100][100];
bool w[26] = {false};
char p;
void Check(char ch) { w[ch - 'A'] = true; }
int main() {
  cin >> n >> m >> p;
  w[p - 'A'] = true;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  bool fp = false;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] == p) {
        fp = true;
        if (i < n - 1) Check(a[i + 1][j]);
        if (i >= 1) Check(a[i - 1][j]);
        if (j < m - 1) Check(a[i][j + 1]);
        if (j >= 1) Check(a[i][j - 1]);
      }
  if (!fp) {
    cout << 0;
    return 0;
  }
  int counter = 0;
  for (int i = 0; i < 26; ++i)
    if (w[i]) ++counter;
  cout << counter - 1;
}
