#include <bits/stdc++.h>
using namespace std;
int n, m;
char ch, grid[101][101];
set<char> s;
void count(int i, int j) {
  if (j != 0 && grid[i][j - 1] != '.' && grid[i][j - 1] != ch)
    s.insert(grid[i][j - 1]);
  if (j != m - 1 && grid[i][j + 1] != ch && grid[i][j + 1] != '.')
    s.insert(grid[i][j + 1]);
  if (i != 0 && grid[i - 1][j] != ch && grid[i - 1][j] != '.')
    s.insert(grid[i - 1][j]);
  if (i != n - 1 && grid[i + 1][j] != ch && grid[i + 1][j] != '.')
    s.insert(grid[i + 1][j]);
}
int main() {
  cin >> n >> m;
  cin >> ch;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> grid[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (grid[i][j] == ch) {
        count(i, j);
      }
  cout << s.size();
  return 0;
}
