#include <bits/stdc++.h>
using namespace std;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
map<char, bool> f;
char C[101][101];
int n, m;
bool inside(int a, int b) {
  return (a >= 0 && a <= n - 1 && b >= 0 && b <= m - 1);
}
int main(int argc, char *argv[]) {
  char c;
  int i, j, cnt = 0;
  scanf("%d", &n);
  scanf("%d", &m);
  cin >> c;
  for (i = 0; i <= n - 1; i++)
    for (j = 0; j <= m - 1; j++) cin >> C[i][j];
  for (i = 0; i <= n - 1; i++)
    for (j = 0; j <= m - 1; j++)
      if (C[i][j] == c) {
        if (inside(i - 1, j) && C[i - 1][j] != '.' && C[i - 1][j] != c &&
            !f[C[i - 1][j]]) {
          f[C[i - 1][j]] = true;
          cnt++;
        }
        if (inside(i + 1, j) && C[i + 1][j] != '.' && C[i + 1][j] != c &&
            !f[C[i + 1][j]]) {
          f[C[i + 1][j]] = true;
          cnt++;
        }
        if (inside(i, j - 1) && C[i][j - 1] != '.' && C[i][j - 1] != c &&
            !f[C[i][j - 1]]) {
          f[C[i][j - 1]] = true;
          cnt++;
        }
        if (inside(i, j + 1) && C[i][j + 1] != '.' && C[i][j + 1] != c &&
            !f[C[i][j + 1]]) {
          f[C[i][j + 1]] = true;
          cnt++;
        }
      }
  cout << cnt << endl;
  return 0;
}
