#include <bits/stdc++.h>
using namespace std;
long long int m, n;
long long int valid(long long int i, long long int j) {
  if ((i >= 0 && i < m) && (j >= 0 && j < n)) return 1;
  return 0;
}
int main() {
  char temp[150], str[150];
  scanf("%lld%lld%s", &m, &n, temp);
  char mat[m][n];
  long long int i, j, rmin = 110, rmax = -1, cmin = 110, cmax = -1, mc = 0;
  for (i = 0; i < m; i++) {
    scanf("%s", str);
    for (j = 0; j < n; j++) {
      mat[i][j] = str[j];
      if (str[j] == temp[0]) {
        if (i < rmin) rmin = i;
        if (i > rmax) rmax = i;
        if (j < cmin) cmin = j;
        if (j > cmax) cmax = j;
      }
    }
  }
  char h[256];
  memset(h, 0, sizeof(h));
  for (i = rmin; i <= rmax; i++) {
    if (valid(i, cmin - 1)) {
      if (mat[i][cmin - 1] != '.' && h[mat[i][cmin - 1]] == 0) {
        h[mat[i][cmin - 1]] = 1;
        mc++;
      }
    }
  }
  for (i = cmin; i <= cmax; i++) {
    if (valid(rmax + 1, i)) {
      if (mat[rmax + 1][i] != '.' && h[mat[rmax + 1][i]] == 0) {
        h[mat[rmax + 1][i]] = 1;
        mc++;
      }
    }
  }
  for (i = rmin; i <= rmax; i++) {
    if (valid(i, cmax + 1)) {
      if (mat[i][cmax + 1] != '.' && h[mat[i][cmax + 1]] == 0) {
        h[mat[i][cmax + 1]] = 1;
        mc++;
      }
    }
  }
  for (i = cmin; i <= cmax; i++) {
    if (valid(rmin - 1, i)) {
      if (mat[rmin - 1][i] != '.' && h[mat[rmin - 1][i]] == 0) {
        h[mat[rmin - 1][i]] = 1;
        mc++;
      }
    }
  }
  printf("%lld\n", mc);
  return 0;
}
