#include <bits/stdc++.h>
const int b = 256;
bool a[b];
int kx[4] = {1, 0, -1, 0};
int ky[4] = {0, 1, 0, -1};
using namespace std;
int main() {
  int n, m;
  char mp[105][105];
  char p;
  cin >> n >> m >> p;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mp[i][j];
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (mp[i][j] != '.' && mp[i][j] != p)
        for (int k = 0; k < 4; ++k) {
          int x = i + kx[k];
          int y = j + ky[k];
          if (x >= 0 && x < n && y >= 0 && y < m && mp[x][y] == p)
            a[mp[i][j]] = 1;
        }
    }
  int res = 0;
  for (int i = 0; i < b; ++i)
    if (a[i]) res++;
  cout << res << endl;
  return 0;
}
