#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m, count = 0;
  bool counted[26] = {false};
  char pre;
  cin >> n >> m >> pre;
  int x[4] = {-1, 0, 0, 1};
  int y[4] = {0, -1, 1, 0};
  counted[pre - 'A'] = true;
  char grid[n][m];
  for (long int i = 0; i < n; i++)
    for (long int j = 0; j < m; j++) cin >> grid[i][j];
  for (long int i = 0; i < n; i++) {
    for (long int j = 0; j < m; j++) {
      if (grid[i][j] == pre) {
        for (int t = 0; t < 4; t++) {
          if (i + x[t] < 0 || i + x[t] >= n) continue;
          if (j + y[t] < 0 || j + y[t] >= m) continue;
          if (grid[i + x[t]][j + y[t]] == '.' ||
              grid[i + x[t]][j + y[t]] == pre)
            continue;
          if (counted[grid[i + x[t]][j + y[t]] - 'A']) continue;
          counted[grid[i + x[t]][j + y[t]] - 'A'] = true;
          count++;
        }
      }
    }
  }
  cout << count;
  return 0;
}
