#include <bits/stdc++.h>
int main(void) {
  int n, m, i, j, l;
  char k;
  int d = 0;
  int found[26] = {0};
  char c, ud = '\0', dd = '\0';
  char desk[101][101];
  scanf("%d %d", &n, &m);
  scanf(" %c", &c);
  for (i = 0; i < n; i++) {
    scanf("%s", desk[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (desk[i][j] == c) {
        if (i != 0) {
          for (k = 'A', l = 0; k < 'Z' + 1; k++, l++) {
            if (desk[i - 1][j] == k && k != c) found[l] = 1;
          }
        }
        if (i != n - 1) {
          for (k = 'A', l = 0; k < 'Z' + 1; k++, l++) {
            if (desk[i + 1][j] == k && k != c) found[l] = 1;
          }
        }
        if (j != 0) {
          for (k = 'A', l = 0; k < 'Z' + 1; k++, l++) {
            if (desk[i][j - 1] == k && k != c) found[l] = 1;
          }
        }
        if (j != m - 1) {
          for (k = 'A', l = 0; k < 'Z' + 1; k++, l++) {
            if (desk[i][j + 1] == k && k != c) found[l] = 1;
          }
        }
      }
    }
  }
  for (i = 0; i < 26; i++) {
    if (found[i] == 1) {
      d++;
    }
  }
  printf("%d", d);
}
