#include <bits/stdc++.h>
using namespace std;
long long prime[1000000];
void sieve() {
  prime[0] = 0;
  prime[1] = 0;
  for (long long i = 2; i < 1000000; i++) prime[i] = 1;
  for (long long i = 2; i * i < 1000000; i++)
    if (prime[i] == 1)
      for (long long j = i * i; j < 1000000; j += i) prime[j] = 0;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i <= floor(sqrt(n)); i++)
    if (n % i == 0) return false;
  return true;
}
long long factorial(long long n) {
  long long f = 1;
  for (long long i = 1; i <= n; i++) f = (f * i) % 1000000007;
  return f;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fastExponentiation(long long n, long long x, long long modulo) {
  long long res = 1;
  while (x > 0) {
    if (x & 1) res = (res * n) % modulo;
    x = x >> 1;
    n = (n * n) % modulo;
  }
  return res;
}
long long power(long long n, long long p) {
  if (p == 0) return 1;
  long long res = power((n * n) % 1000000007, p / 2);
  if (p % 2 == 1) res = (n * res) % 1000000007;
  return res;
}
bool isPowerOfTwo(long long n) { return n && (!(n & (n - 1))); }
bool isSet(long long n, long long i) { return n & (1 << i); }
bool valid_coordinate(long long x, long long y, long long n, long long m) {
  if (x < 0 || y < 0)
    return false;
  else if (x >= n || y >= m)
    return false;
  else
    return true;
}
long long check(long long a, long long b) {
  if (a % 2 == b % 2)
    return 1;
  else if (abs(a - b) == 1)
    return 1;
  return 0;
}
long long sod(long long n) {
  long long sum = 0;
  while (n) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}
void solve() {
  long long n, m;
  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];
  }
  map<char, long long> desk;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == c) {
        if (valid_coordinate(i - 1, j, n, m)) {
          if (a[i - 1][j] != c && a[i - 1][j] != '.') desk[a[i - 1][j]]++;
        }
        if (valid_coordinate(i + 1, j, n, m)) {
          if (a[i + 1][j] != c && a[i + 1][j] != '.') desk[a[i + 1][j]]++;
        }
        if (valid_coordinate(i, j - 1, n, m)) {
          if (a[i][j - 1] != c && a[i][j - 1] != '.') desk[a[i][j - 1]]++;
        }
        if (valid_coordinate(i, j + 1, n, m)) {
          if (a[i][j + 1] != c && a[i][j + 1] != '.') desk[a[i][j + 1]]++;
        }
      }
    }
  }
  cout << desk.size() << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(0) << fixed;
  solve();
  return 0;
}
