#include <bits/stdc++.h>
int main() {
  int row, col, i, j, check = 0, cnt = 0;
  int index[100][100];
  char color;
  scanf("%i %i %c", &row, &col, &color);
  char office[row][col];
  for (i = 0; i < row; i++) scanf("%s", &office[i]);
  for (i = 0; i < row; i++)
    for (j = 0; j < col; j++)
      if (office[i][j] == color) cnt++;
  char neighbors[cnt * 4];
  cnt = 0;
  for (i = 0; i < row; i++)
    for (j = 0; j < col; j++)
      if (office[i][j] == color) {
        if (i - 1 >= 0) {
          neighbors[cnt] = office[i - 1][j];
          cnt++;
        }
        if (i + 1 < row) {
          neighbors[cnt] = office[i + 1][j];
          cnt++;
        }
        if (j - 1 >= 0) {
          neighbors[cnt] = office[i][j - 1];
          cnt++;
        }
        if (j + 1 < col) {
          neighbors[cnt] = office[i][j + 1];
          cnt++;
        }
      }
  for (i = 0; i < cnt; i++) {
    if (neighbors[i] == color) neighbors[i] = '.';
    if (neighbors[i] != color && neighbors[i] != '.')
      for (j = 1 + i; j < cnt; j++) {
        if (neighbors[i] == neighbors[j]) neighbors[i] = '.';
      }
  }
  for (i = 0; i < cnt; i++)
    if (neighbors[i] != '.') check++;
  printf("%i", check);
  return 0;
}
