#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, i, j, arr[105][105], t, t1, count = 0;
  char c, d, y;
  map<char, int> m;
  vector<int> v, v1;
  cin >> a >> b >> c;
  for (i = 0; i < a; i++) {
    for (j = 0; j < b; j++) {
      cin >> d;
      arr[i][j] = d;
      m[d] = 0;
      if (d == c) {
        v.push_back(i);
        v1.push_back(j);
      }
    }
  }
  for (i = 0; i < v.size(); i++) {
    t = v[i];
    t1 = v1[i];
    if (t - 1 >= 0 && t - 1 < a) {
      y = arr[t - 1][t1];
      if (m[y] == 0 && y != c && y != '.') {
        count++;
        m[y] = 1;
      }
    }
    if (t + 1 >= 0 && t + 1 < a) {
      y = arr[t + 1][t1];
      if (m[y] == 0 && y != c && y != '.') {
        count++;
        m[y] = 1;
      }
    }
    if (t1 - 1 >= 0 && t1 - 1 < b) {
      y = arr[t][t1 - 1];
      if (m[y] == 0 && y != c && y != '.') {
        count++;
        m[y] = 1;
      }
    }
    if (t1 + 1 >= 0 && t1 + 1 < b) {
      y = arr[t][t1 + 1];
      if (m[y] == 0 && y != c && y != '.') {
        count++;
        m[y] = 1;
      }
    }
  }
  cout << count << endl;
  return 0;
}
