#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, t, m, ctr = 0, i, j;
  char ch;
  cin >> n >> m >> ch;
  char a[n + 2][m + 2];
  for (i = 0; i < n + 2; i++) {
    for (j = 0; j < m + 2; j++) a[i][j] = '.';
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) cin >> a[i][j];
  }
  map<char, long long int> ma;
  ma[ch] = 1;
  ma['.'] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == ch) {
        if (ma[a[i - 1][j]] != 1) {
          ctr++;
          ma[a[i - 1][j]] = 1;
        }
        if (ma[a[i + 1][j]] != 1) {
          ctr++;
          ma[a[i + 1][j]] = 1;
        }
        if (ma[a[i][j + 1]] != 1) {
          ctr++;
          ma[a[i][j + 1]] = 1;
        }
        if (ma[a[i][j - 1]] != 1) {
          ctr++;
          ma[a[i][j - 1]] = 1;
        }
      }
    }
  }
  cout << ctr;
}
