#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
char arr[101][101];
bool visited[101][101] = {0};
set<char> st;
int n, m;
char a;
bool valid(int i, int j) { return i < n && i >= 0 && j < m && j >= 0; }
void solve(int i, int j) {
  cerr << i << " " << j << " ";
  visited[i][j] = 1;
  if (arr[i][j] == a) {
    for (int idx = 0; idx < 4; idx++) {
      int ddx = i + dx[idx];
      int ddy = j + dy[idx];
      if (valid(ddx, ddy) && !visited[ddx][ddy]) {
        solve(ddx, ddy);
      }
    }
  } else if (arr[i][j] != '.') {
    st.insert(arr[i][j]);
  }
}
int main() {
  cin >> n >> m >> a;
  int starti, startj;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == a) {
        starti = i;
        startj = j;
      }
    }
  }
  solve(starti, startj);
  cout << st.size();
  return 0;
}
