#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
set<char> st;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  char c;
  cin >> c;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == c) {
        if (i != 0 and a[i - 1][j] != c and a[i - 1][j] != '.') {
          st.insert(a[i - 1][j]);
        }
        if (i != n - 1 and a[i + 1][j] != c and a[i + 1][j] != '.') {
          st.insert(a[i + 1][j]);
        }
        if (j != 0 and a[i][j - 1] != c and a[i][j - 1] != '.') {
          st.insert(a[i][j - 1]);
        }
        if (j != m - 1 and a[i][j + 1] != c and a[i][j + 1] != '.') {
          st.insert(a[i][j + 1]);
        }
      }
    }
  }
  cout << st.size() << "\n";
  return 0;
}
