#include <bits/stdc++.h>
using namespace std;
static long long int n, m;
static char c;
static vector<vector<char> > arr;
long long int solve(void) {
  int sx, sy, ex, ey;
  bool flag = false;
  for (int i = 0; i < n && !flag; i++)
    for (int j = 0; j < m && !flag; j++)
      if (arr[i][j] == c) {
        sx = i, sy = j;
        flag = true;
      }
  int i, j;
  for (ex = sx; ex < n && arr[ex][sy] == c; ex++)
    ;
  for (ey = sy; ey < m && arr[sx][ey] == c; ey++)
    ;
  vector<bool> vis(26, false);
  long long int res = 0;
  for (int i = sx; sy > 0 && i < ex; i++) {
    if (arr[i][sy - 1] != '.' && !vis[arr[i][sy - 1] - 'A']) {
      res++;
      vis[arr[i][sy - 1] - 'A'] = true;
    }
  }
  for (int i = sx; ey < m && i < ex; i++) {
    if (arr[i][ey] != '.' && !vis[arr[i][ey] - 'A']) {
      res++;
      vis[arr[i][ey] - 'A'] = true;
    }
  }
  for (int j = sy; j < ey && sx > 0; j++) {
    if (arr[sx - 1][j] != '.' && !vis[arr[sx - 1][j] - 'A']) {
      res++;
      vis[arr[sx - 1][j] - 'A'] = true;
    }
  }
  for (int j = sy; j < ey && ex < n; j++) {
    if (arr[ex][j] != '.' && !vis[arr[ex][j] - 'A']) {
      res++;
      vis[arr[ex][j] - 'A'] = true;
    }
  }
  return res;
}
int main() {
  while (cin >> n >> m >> c) {
    arr.resize(n, vector<char>(m));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> arr[i][j];
    cout << solve() << "\n";
  }
  return 0;
}
