#include <bits/stdc++.h>
using namespace std;
set<char> Check;
int n, m;
void Ck(string T[], int r, int c) {
  if (r - 1 >= 0 && T[r - 1][c] != T[r][c] && T[r - 1][c] != '.')
    Check.insert(T[r - 1][c]);
  if (r + 1 < n && T[r + 1][c] != T[r][c] && T[r + 1][c] != '.')
    Check.insert(T[r + 1][c]);
  if (c + 1 < m && T[r][c + 1] != T[r][c] && T[r][c + 1] != '.')
    Check.insert(T[r][c + 1]);
  if (c - 1 >= 0 && T[r][c - 1] != T[r][c] && T[r][c - 1] != '.')
    Check.insert(T[r][c - 1]);
}
int main() {
  char c;
  cin >> n >> m >> c;
  string Text[n];
  for (int i = 0; i < n; i++) {
    cin >> Text[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (Text[i][j] == c) Ck(Text, i, j);
    }
  }
  cout << Check.size();
  return 0;
}
