#include <bits/stdc++.h>
int a[27];
int main() {
  int n, m, i, j, z = 0;
  char c[102][102], d;
  scanf("%d %d %c", &n, &m, &d);
  for (i = 0; i < n; i++) {
    scanf("%s", c[i]);
  }
  a[d - 'A' + 1] = 2;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (c[i][j] == d) {
        if (i > 0 && c[i - 1][j] != d && c[i - 1][j] >= 'A' &&
            c[i - 1][j] <= 'Z')
          a[c[i - 1][j] - 'A' + 1] = 1;
        if (i < n - 1 && c[i + 1][j] != d && c[i + 1][j] >= 'A' &&
            c[i + 1][j] <= 'Z')
          a[c[i + 1][j] - 'A' + 1] = 1;
        if (j > 0 && c[i][j - 1] != d && c[i][j - 1] >= 'A' &&
            c[i][j - 1] <= 'Z')
          a[c[i][j - 1] - 'A' + 1] = 1;
        if (j < m - 1 && c[i][j + 1] != d && c[i][j + 1] >= 'A' &&
            c[i][j + 1] <= 'Z')
          a[c[i][j + 1] - 'A' + 1] = 1;
      }
    }
  }
  for (i = 1; i <= 26; i++) {
    if (a[i] == 1) z++;
  }
  printf("%d", z);
  return 0;
}
