#include <bits/stdc++.h>
char s[102][102];
int main(void) {
  int n, m;
  char c;
  scanf("%d %d %c\n", &n, &m, &c);
  for (int i = 0; i <= m + 1; i++) s[0][i] = '.';
  for (int i = 1; i <= n; i++) {
    s[i][0] = '.';
    scanf("%s", s[i] + 1);
    s[i][m + 1] = '.';
  }
  for (int i = 0; i <= m + 1; i++) s[n + 1][i] = '.';
  int xs = -1, ys = -1, xe = -1, ye = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == c) {
        if (xs < 0) {
          xs = j;
          ys = i;
        }
        xe = j;
        ye = i;
      }
  int t = 0;
  int f = 0;
  for (int i = xs; i <= xe; i++) {
    char r = s[ys - 1][i];
    if (r != '.' && (((f >> (r - 'A')) & 1) == 0)) {
      t++;
      f |= (1 << (r - 'A'));
    }
  }
  f = 0;
  for (int i = xs; i <= xe; i++) {
    char r = s[ye + 1][i];
    if (r != '.' && (((f >> (r - 'A')) & 1) == 0)) {
      t++;
      f |= (1 << (r - 'A'));
    }
  }
  f = 0;
  for (int i = ys; i <= ye; i++) {
    char r = s[i][xs - 1];
    if (r != '.' && (((f >> (r - 'A')) & 1) == 0)) {
      t++;
      f |= (1 << (r - 'A'));
    }
  }
  f = 0;
  for (int i = ys; i <= ye; i++) {
    char r = s[i][xe + 1];
    if (r != '.' && (((f >> (r - 'A')) & 1) == 0)) {
      t++;
      f |= (1 << (r - 'A'));
    }
  }
  printf("%d\n", t);
  return 0;
}
