#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];
    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) {
          s.insert(a[max(0LL, i - 1)][max(0LL, j)]);
          s.insert(a[min(n - 1, i + 1)][max(0LL, j)]);
          s.insert(a[max(0LL, i)][min(m - 1, j + 1)]);
          s.insert(a[max(0LL, i)][max(0LL, j - 1)]);
          s.insert(a[max(0LL, i)][max(0LL, j)]);
        }
      }
    }
    s.insert('.');
    s.insert(c);
    cout << int(s.size()) - 2 << endl;
  }
  return 0;
}
