#include <bits/stdc++.h>
using namespace std;
int vis[110][110];
int vis1[110];
struct node {
  int x;
  int y;
} a1[100010];
int main() {
  int i, j, cot, n, m, k;
  char c[5];
  char a[110][110];
  while (~scanf("%d%d%s", &n, &m, &c)) {
    k = 0;
    memset(vis, 0, sizeof(vis));
    memset(vis1, 0, sizeof(vis1));
    for (i = 0; i < n; i++) {
      scanf("%s", a[i]);
      for (j = 0; j < m; j++) {
        if (a[i][j] == c[0]) {
          a1[k].x = i;
          a1[k].y = j;
          vis[i][j] = 1;
          vis1[a[i][j] - '0'] = 1;
          k++;
        }
      }
    }
    cot = 0;
    for (int k1 = 0; k1 < k; k1++) {
      i = a1[k1].x;
      j = a1[k1].y;
      if (a[i + 1][j] != '.' && !vis1[a[i + 1][j] - '0'] && i + 1 < n) {
        cot++;
        vis1[a[i + 1][j] - '0'] = 1;
      }
      if (a[i - 1][j] != '.' && !vis1[a[i - 1][j] - '0'] && i - 1 >= 0) {
        cot++;
        vis1[a[i - 1][j] - '0'] = 1;
      }
      if (a[i][j + 1] != '.' && !vis1[a[i][j + 1] - '0'] && j + 1 < m) {
        cot++;
        vis1[a[i][j + 1] - '0'] = 1;
      }
      if (a[i][j - 1] != '.' && !vis1[a[i][j - 1] - '0'] && j - 1 >= 0) {
        cot++;
        vis1[a[i][j - 1] - '0'] = 1;
      }
    }
    printf("%d\n", cot);
  }
  return 0;
}
