#include <bits/stdc++.h>
int main() {
  int n, m;
  bool flag[26];
  char color;
  std::cin >> n >> m >> color;
  int i, j, count = 0;
  for (i = 0; i < 26; i++) flag[i] = false;
  char plan[n][m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) std::cin >> plan[i][j];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (plan[i][j] == color) {
        if (i - 1 >= 0) {
          if ((plan[i - 1][j] != color && plan[i - 1][j] != '.') &&
              !flag[plan[i - 1][j] - 'A']) {
            count++;
            flag[plan[i - 1][j] - 'A'] = true;
          }
        }
        if (j - 1 >= 0) {
          if ((plan[i][j - 1] != color && plan[i][j - 1] != '.') &&
              !flag[plan[i][j - 1] - 'A']) {
            count++;
            flag[plan[i][j - 1] - 'A'] = true;
          }
        }
        if (i + 1 < n) {
          if ((plan[i + 1][j] != color && plan[i + 1][j] != '.') &&
              !flag[plan[i + 1][j] - 'A']) {
            count++;
            flag[plan[i + 1][j] - 'A'] = true;
          }
        }
        if (j + 1 < m) {
          if ((plan[i][j + 1] != color && plan[i][j + 1] != '.') &&
              !flag[plan[i][j + 1] - 'A']) {
            count++;
            flag[plan[i][j + 1] - 'A'] = true;
          }
        }
      }
    }
  }
  std::cout << count << std::endl;
  return 0;
}
