#include <bits/stdc++.h>
using namespace std;
int n, m, ans, b[350];
char l, a[150][150];
int main() {
  int i, j;
  cin >> n >> m >> l;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (a[i][j] == l)
        b[a[i - 1][j]] = b[a[i + 1][j]] = b[a[i][j - 1]] = b[a[i][j + 1]] = 1;
  for (i = 'A'; i <= 'Z'; i++) ans += b[i];
  cout << ans - b[l] << endl;
  return 0;
}
