#include <bits/stdc++.h>
using namespace std;
int n, m, deputies = 0;
char president;
char arr[100][100];
bool vis[100][100];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool is_valid(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return 1;
  return 0;
}
int main() {
  cin >> n >> m >> president;
  memset(arr, 0, sizeof(arr));
  memset(vis, 0, sizeof(vis));
  vector<pair<int, int>> xys;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '.') vis[i][j] = 1;
      if (arr[i][j] == president) xys.push_back(make_pair(i, j));
    }
  }
  vector<char> depu;
  bool flag = false;
  for (int i = 0; i < (int)xys.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (is_valid(xys[i].first + dx[j], xys[i].second + dy[j]) &&
          arr[xys[i].first + dx[j]][xys[i].second + dy[j]] != president &&
          arr[xys[i].first + dx[j]][xys[i].second + dy[j]] != '.') {
        flag = false;
        for (int c = 0; c < (int)depu.size(); c++) {
          if (depu[c] == arr[xys[i].first + dx[j]][xys[i].second + dy[j]]) {
            flag = true;
            break;
          }
        }
        if (!flag) {
          deputies++;
          depu.push_back(arr[xys[i].first + dx[j]][xys[i].second + dy[j]]);
        }
      }
    }
  }
  cout << deputies;
  return 0;
}
