#include <bits/stdc++.h>
int m, n, b[150], count = 0;
char c, a[1001][1001];
void BFS(int x, int y) {
  int k, l, g, h;
  k = x + 1;
  l = x - 1;
  g = y + 1;
  h = y - 1;
  if (b[a[x][g]] == 0 && a[x][g] != '.' && a[x][g] != c && g < n) {
    b[a[x][g]] = 1;
    count++;
  }
  if (b[a[x][h]] == 0 && a[x][h] != '.' && a[x][h] != c && h >= 0) {
    b[a[x][h]] = 1;
    count++;
  }
  if (b[a[k][y]] == 0 && a[k][y] != '.' && a[k][y] != c && k < m) {
    b[a[k][y]] = 1;
    count++;
  }
  if (b[a[l][y]] == 0 && a[l][y] != '.' && a[l][y] != c && l >= 0) {
    b[a[l][y]] = 1;
    count++;
  }
}
int main(void) {
  int i, j;
  memset(a, '0', sizeof(a));
  memset(b, 0, sizeof(b));
  scanf("%d %d %c", &m, &n, &c);
  for (i = 0; i < m; i++) {
    scanf("%s", a[i]);
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (a[i][j] == c) BFS(i, j);
    }
  }
  printf("%d", count);
  return 0;
}
