#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  char pr;
  string ans = "";
  cin >> n >> m >> pr;
  char office[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> office[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (office[i][j] == pr) {
        if (office[i][j - 1] != '.' && office[i][j - 1] != pr && j != 0) {
          ans += office[i][j - 1];
        }
        if (office[i - 1][j] != '.' && office[i - 1][j] != pr && i != 0) {
          ans += office[i - 1][j];
        }
        if (office[i][j + 1] != '.' && office[i][j + 1] != pr && j != m - 1) {
          ans += office[i][j + 1];
        }
        if (office[i + 1][j] != '.' && office[i + 1][j] != pr && i != n - 1) {
          ans += office[i + 1][j];
        }
      }
    }
  }
  int alphabet[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int cnt = 0;
  for (int i = 0; i < ans.size(); i++) {
    alphabet[ans[i] - 'A']++;
  }
  for (int i = 0; i < 26; i++) {
    if (alphabet[i] > 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
