#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592654;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int main() {
  fast();
  int x, y;
  char z;
  cin >> x >> y >> z;
  set<char> st;
  char arr[100][100];
  for (int(i) = 0; (i) < (long long)(x); (i)++) {
    for (int(j) = 0; (j) < (long long)(y); (j)++) cin >> arr[i][j];
  }
  for (int(i) = 0; (i) < (long long)(x); (i)++) {
    for (int(j) = 0; (j) < (long long)(y); (j)++) {
      if (arr[i][j] == z) {
        if (j < y - 1) {
          if (isalpha(arr[i][j + 1]) && arr[i][j + 1] != z)
            st.insert(arr[i][j + 1]), arr[i][j + 1] = '.';
        }
        if (j > 0) {
          if (isalpha(arr[i][j - 1]) && arr[i][j - 1] != z)
            st.insert(arr[i][j - 1]), arr[i][j - 1] = '.';
        }
        if (i < x - 1) {
          if (isalpha(arr[i + 1][j]) && arr[i + 1][j] != z)
            st.insert(arr[i + 1][j]), arr[i + 1][j] = '.';
        }
        if (i > 0) {
          if (isalpha(arr[i - 1][j]) && arr[i - 1][j] != z)
            st.insert(arr[i - 1][j]), arr[i - 1][j] = '.';
        }
      }
    }
  }
  cout << st.size() << endl;
  return 0;
}
