#include <bits/stdc++.h>
const int Const[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}};
bool mark[26];
char s[101][102];
int main() {
  int n, m, ans = 0;
  char c;
  scanf("%d %d %c", &n, &m, &c);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] == c)
        for (int k = 0, x, y; k < 4; ++k) {
          x = i + Const[0][k];
          y = j + Const[1][k];
          if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] != '.' &&
              s[x][y] != c && !mark[s[x][y] - 'A'])
            mark[s[x][y] - 'A'] = 1;
        }
  for (int i = 0; i < 26; ++i) ans += mark[i];
  printf("%d", ans);
  return 0;
}
