#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e2 + 5;
void build() { return; }
int n, m;
char co[5];
char store[MAX][MAX];
void Init() {
  scanf("%d %d %s", &n, &m, co);
  for (int i = 0; i < (n); ++i) scanf("%s", store[i]);
  return;
}
bitset<MAX> check[MAX];
set<char> ans;
int rr[] = {0, 1, 0, -1};
int cc[] = {1, 0, -1, 0};
void sol2(int r, int c) {
  for (int i = 0; i < (4); ++i) {
    int nr = r + rr[i];
    int nc = c + cc[i];
    if (nr >= 0 && nr < n && nc >= 0 && nc < m) {
      if (store[nr][nc] != '.') ans.insert(store[nr][nc]);
    }
  }
  return;
}
void sol() {
  int r, c;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      if (store[i][j] == co[0]) {
        sol2(i, j);
      }
    }
  ans.insert(co[0]);
  printf("%d", (int)ans.size() - 1);
  return;
}
int main(void) {
  Init();
  build();
  sol();
  return 0;
}
