#include <bits/stdc++.h>
using namespace std;
int x[] = {-1, 1, 0, 0};
int y[] = {0, 0, -1, 1};
int main() {
  int m, n;
  char c;
  cin >> m >> n >> c;
  vector<string> s(m);
  for (int i = 0; i < m; i++) cin >> s[i];
  queue<int> q;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (s[i][j] == c) {
        q.push(i);
        q.push(j);
      }
    }
  }
  set<char> seen;
  seen.insert(c);
  while (!q.empty()) {
    int I = q.front();
    q.pop();
    int J = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int xx = I + x[k], yy = J + y[k];
      if (xx >= 0 && yy >= 0 && xx < m && yy < n) {
        if (isupper(s[xx][yy])) seen.insert(s[xx][yy]);
      }
    }
  }
  printf("%d\n", (int)seen.size() - 1);
}
