#include <bits/stdc++.h>
int dx4[] = {0, 0, -1, 1};
int dy4[] = {-1, 1, 0, 0};
bool valid(int r, int c, int x, int y) {
  if (x >= 1 && x <= r && y >= 1 && y <= c) return 1;
  return 0;
}
using namespace std;
char a[1000][1000];
map<char, int> v;
int main() {
  int n, m;
  string ch;
  memset(a, '.', sizeof(a));
  cin >> n >> m >> ch;
  string s[n + 2];
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 1; j <= m; j++) a[i][j] = s[i][j - 1];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c = a[i][j];
      if (v[c] == 1) continue;
      if (c == ch[0]) {
        if ((a[i][j - 1] != '.' && a[i][j - 1] != ch[0])) {
          if (v[a[i][j - 1]] == 0) ans++;
          v[a[i][j - 1]] = 1;
        }
        if ((a[i][j + 1] != '.' && a[i][j + 1] != ch[0])) {
          if (v[a[i][j + 1]] == 0) ans++;
          v[a[i][j + 1]] = 1;
        }
        if ((a[i - 1][j] != '.' && a[i - 1][j] != ch[0])) {
          if (v[a[i - 1][j]] == 0) ans++;
          v[a[i - 1][j]] = 1;
        }
        if (a[i + 1][j] != '.' && a[i + 1][j] != ch[0]) {
          if (v[a[i + 1][j]] == 0) ans++;
          v[a[i + 1][j]] = 1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
