#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= 998244253LL;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 998244253LL;
    a = a * a % 998244253LL;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b, i, j, ans = 0;
  char c;
  bool arr[256] = {};
  cin >> a >> b >> c;
  arr[c] = arr['.'] = 1;
  char second[a][b];
  for (i = 0; i < a; i++) cin >> second[i];
  for (i = 0; i < a; i++)
    for (j = 0; j < b; j++) {
      if (second[i][j] == c) {
        if (i > 0 && !arr[second[i - 1][j]]) ans++, arr[second[i - 1][j]] = 1;
        if (j > 0 && !arr[second[i][j - 1]]) ans++, arr[second[i][j - 1]] = 1;
        if (i < a - 1 && !arr[second[i + 1][j]])
          ans++, arr[second[i + 1][j]] = 1;
        if (j < b - 1 && !arr[second[i][j + 1]])
          ans++, arr[second[i][j + 1]] = 1;
      }
    }
  cout << ans;
  return 0;
}
