#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char mp[110][110];
int a[128];
int check(int x, int y, char c) {
  if (mp[x + 1][y] == c || mp[x][y + 1] == c || mp[x - 1][y] == c ||
      mp[x][y - 1] == c)
    return 1;
  return 0;
}
int main() {
  int n, m;
  char c;
  scanf("%d %d %c", &n, &m, &c);
  getchar();
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mp[i][j] != '.' && mp[i][j] != c)
        if (a[mp[i][j]] == 0)
          if (check(i, j, c)) {
            ans++;
            a[mp[i][j]] = 1;
          }
  printf("%d\n", ans);
}
