#include <bits/stdc++.h>
using namespace std;
int x[4] = {0, 0, -1, 1};
int y[4] = {1, -1, 0, 0};
char t[110][110], z, z1;
int n, m;
bool done[2 * 110];
bool ok(int i, int nrw, int nrk) {
  return x[i] + nrw >= 0 && x[i] + nrw < n && y[i] + nrk >= 0 && y[i] + nrk < m;
}
int main() {
  scanf("%d%d%c%c%c", &n, &m, &z, &z, &z1);
  done[int(z)] = 1;
  for (int i = 0; i < n; i++) scanf("%s", t[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (t[i][j] == z)
        for (int l = 0; l < 4; l++)
          if (ok(l, i, j)) done[int(t[x[l] + i][y[l] + j])] = 1;
  int ile = 0;
  for (int i = 65; i < 98; i++)
    if (done[i]) ile++;
  printf("%d\n", ile - 1);
  return 0;
}
