#include <bits/stdc++.h>
using namespace std;
const int kmax = 105;
char a[kmax][kmax], p;
int n, m, ans;
bool b[kmax * 2];
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == p) {
        b[a[i - 1][j]] = b[a[i][j - 1]] = b[a[i + 1][j]] = b[a[i][j + 1]] = 1;
      }
    }
  }
  for (int i = 'A'; i <= 'Z'; i++) {
    ans += b[i] && i != p;
  }
  cout << ans;
  return 0;
}
