#include <bits/stdc++.h>
const int SIZE = 1e2 + 5;
using namespace std;
bool cnt[30];
char arr[SIZE][SIZE];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int n, m;
  char c;
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == c && i - 1 > -1 && arr[i - 1][j] != '.')
        cnt[arr[i - 1][j] - 'A'] = 1;
      if (arr[i][j] == c && j - 1 > -1 && arr[i][j - 1] != '.')
        cnt[arr[i][j - 1] - 'A'] = 1;
      if (arr[i][j] == c && i + 1 < n && arr[i + 1][j] != '.')
        cnt[arr[i + 1][j] - 'A'] = 1;
      if (arr[i][j] == c && j + 1 < m && arr[i][j + 1] != '.')
        cnt[arr[i][j + 1] - 'A'] = 1;
    }
  }
  int Ans = 0;
  for (int i = 0; i < 27; i++) Ans += (cnt[i] == 1 && (char)(i + 'A') != c);
  cout << Ans;
}
