#include <bits/stdc++.h>
using namespace std;
void fastscan(int &number) {
  bool negative = false;
  register int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
int check(int x, int y, int n, int m) {
  if (x < 0 || y < 0 || x >= n || y >= m) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  char p;
  cin >> p;
  string grid[n];
  for (int i = 0; i < n; i++) cin >> grid[i];
  vector<pair<int, int> > v;
  set<char> s;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < grid[i].size(); ++j) {
      if (grid[i][j] == p)
        v.push_back(make_pair(i, j));
      else if (grid[i][j] != '.')
        s.insert(grid[i][j]);
    }
  }
  int x, y;
  int ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    x = v[i].first, y = v[i].second;
    if (check(x, y + 1, n, m) && grid[x][y + 1] != '.') {
      if (s.find(grid[x][y + 1]) != s.end()) {
        ans++;
        s.erase(grid[x][y + 1]);
      }
    }
    if (check(x + 1, y, n, m) && grid[x + 1][y] != '.') {
      if (s.find(grid[x + 1][y]) != s.end()) {
        ans++;
        s.erase(grid[x + 1][y]);
      }
    }
    if (check(x - 1, y, n, m) && grid[x - 1][y] != '.') {
      if (s.find(grid[x - 1][y]) != s.end()) {
        ans++;
        s.erase(grid[x - 1][y]);
      }
    }
    if (check(x, y - 1, n, m) && grid[x][y - 1] != '.') {
      if (s.find(grid[x][y - 1]) != s.end()) {
        ans++;
        s.erase(grid[x][y - 1]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
