#include <bits/stdc++.h>
using namespace std;
char mt[128][128], c;
int n, m, cnt;
void dfs(int x, int y, char color) {
  if (mt[x][y] != color) return;
  mt[x][y] = '.';
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if (i && j) continue;
      dfs(x + i, y + j, color);
    }
  }
}
int main() {
  cin >> n >> m >> c;
  for (int i = 1; i <= n; i++) {
    scanf("%s", mt[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mt[i][j] == c) {
        for (int x = -1; x <= 1; x++) {
          for (int y = -1; y <= 1; y++) {
            if (x && y) continue;
            if (mt[i + x][j + y] && mt[i + x][j + y] != '.' &&
                mt[i + x][j + y] != c) {
              cnt++;
              dfs(i + x, j + y, mt[i + x][j + y]);
            }
          }
        }
      }
    }
  }
  cout << cnt;
}
