#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e5 + 5;
char a[1002][1002];
map<char, bool> vis;
void solve() {
  int n, m, ans = 0;
  char c;
  cin >> n >> m >> c;
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < m + 1; j++) cin >> a[i][j];
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (a[i][j] == c) {
        vis[a[i - 1][j]] = vis[a[i][j - 1]] = vis[a[i + 1][j]] =
            vis[a[i][j + 1]] = true;
      }
    }
  }
  for (char z = 'A'; z <= 'Z'; z++) ans += vis[z];
  cout << ans - vis[c];
}
int main() {
  solve();
  cout << "\n";
  return 0;
}
