#include <bits/stdc++.h>
using namespace std;
void p(long long a[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long i, j, k, n, m, x, y;
    char c;
    cin >> n >> m >> c;
    char a[n][m];
    int r[] = {0, 0, -1, 1}, s[] = {-1, 1, 0, 0};
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    set<char> S;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (a[i][j] == c) {
          for (k = 0; k < 4; k++) {
            x = i + r[k];
            y = j + s[k];
            if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] != '.' &&
                a[x][y] != c)
              S.insert(a[x][y]);
          }
        }
      }
    }
    cout << S.size() << endl;
  }
  return 0;
}
