#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
void rw() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  char p;
  cin >> n >> m >> p;
  map<char, long long> s;
  char a[n + 1][m + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == p) {
        if (j - 1 > 0) s[a[i][j - 1]] = 1;
        if (j + 1 <= m) s[a[i][j + 1]] = 1;
        if (i - 1 > 0) s[a[i - 1][j]] = 1;
        if (i + 1 <= n) s[a[i + 1][j]] = 1;
      }
    }
  }
  s.erase('.');
  s.erase(p);
  n = s.size();
  cout << n;
  return 0;
}
