#include <bits/stdc++.h>
using namespace std;
char mat[110][110];
long long n, m;
char c;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
set<char> st;
void dfs(long long i, long long j) {
  if (i < 0 or j < 0 or i >= n or j >= m) return;
  if (mat[i][j] == '.') return;
  st.insert(mat[i][j]);
  if (mat[i][j] == c) {
    mat[i][j] = '.';
    for (long long k = 0; k < 4; k++) {
      long long x = i + dx[k];
      long long y = j + dy[k];
      if (mat[x][y] != '.') dfs(x, y);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> c;
  long long x, y;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> mat[i][j];
      if (c == mat[i][j]) x = i, y = j;
    }
  }
  dfs(x, y);
  cout << st.size() - 1 << endl;
  return 0;
}
