#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y;
int ans = 0;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
map<char, bool> map1;
char c;
char s[110][110];
bool vis[110][110] = {0};
void dfs(int x, int y) {
  if (vis[x][y]) return;
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    if (x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < m &&
        s[x + dx[i]][y + dy[i]] != '.') {
      if (s[x + dx[i]][y + dy[i]] != c)
        map1[s[x + dx[i]][y + dy[i]]] = true;
      else
        dfs(x + dx[i], y + dy[i]);
    }
  }
}
int main() {
  memset(s, 0, sizeof(s));
  scanf("%d%d%*c%c", &n, &m, &c);
  for (int i = 0; i < n; i++) {
    getchar();
    for (int j = 0; j < m; j++) {
      scanf("%c", &s[i][j]);
      if (s[i][j] == c) {
        x = i;
        y = j;
      }
    }
  }
  dfs(x, y);
  printf("%d\n", map1.size());
  return 0;
}
