#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  char c;
  cin >> n >> m >> c;
  string room[n], str;
  for (int i = 0; i < n; i++) {
    cin >> str;
    room[i] = str;
  }
  unordered_set<char> s;
  for (int i = 0; i < n; i++)
    for (int j = 1; j < m; j++)
      if (room[i][j - 1] == c or room[i][j] == c) {
        s.insert(room[i][j - 1]);
        s.insert(room[i][j]);
      }
  for (int i = 1; i < n; i++)
    for (int j = 0; j < m; j++)
      if (room[i - 1][j] == c or room[i][j] == c) {
        s.insert(room[i - 1][j]);
        s.insert(room[i][j]);
      }
  if (s.count(c)) s.erase(s.find(c));
  if (s.count('.')) s.erase(s.find('.'));
  cout << s.size();
}
