#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2 + 5;
const int oo = 1e9 + 35;
char grid[MAX][MAX];
int vis[30];
int main() {
  int n, m;
  char c;
  cin >> n >> m >> c;
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == c) v.push_back({i, j});
    }
  }
  int s = 0;
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  for (auto &it : v) {
    for (int i = 0; i < 4; i++) {
      pair<int, int> u = {it.first + dx[i], it.second + dy[i]};
      if (u.first >= 0 && u.first < n && u.second < m && u.second >= 0 &&
          grid[u.first][u.second] != '.' && grid[u.first][u.second] != c) {
        int x = grid[u.first][u.second] - 'A';
        if (!vis[x]) {
          s++;
          vis[x] = 1;
        }
      }
    }
  }
  cout << s;
  return 0;
}
