#include <bits/stdc++.h>
using namespace std;
long long limit = 4294967296;
int MOD = 1000000007;
template <typename T>
void print(const T& x) {
  cerr << x << ' ';
}
template <typename T1, typename... T2>
void print(const T1& first, const T2&... rest) {
  print(first);
  print(rest...);
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
void solve() {
  int n, m;
  cin >> n >> m;
  char p;
  cin >> p;
  bool flag[27];
  memset(flag, false, sizeof(flag));
  flag[p - 'A'] = true;
  char room[n + 2][m + 2];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> room[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (room[i][j] == p) {
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (x >= 0 && x < n && y >= 0 and y < m && room[x][y] >= 'A' &&
              room[x][y] <= 'Z') {
            flag[room[x][y] - 'A'] = true;
          }
        }
      }
    }
  }
  int c = 0;
  for (int i = 0; i <= 26; i++)
    if (flag[i] == true) c++;
  cout << c - 1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
