#include <bits/stdc++.h>
int pct(int x) { return __builtin_popcount(x); }
using namespace std;
char grid[101][101];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  char c;
  cin >> n >> m >> c;
  int row;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  set<char> s;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] != c && grid[i][j] != '.') {
        if (i + 1 < n && grid[i + 1][j] == c && s.find(grid[i][j]) == s.end()) {
          ans++;
          s.insert(grid[i][j]);
        } else if (i - 1 >= 0 && grid[i - 1][j] == c &&
                   s.find(grid[i][j]) == s.end()) {
          ans++;
          s.insert(grid[i][j]);
        } else if (j + 1 < m && grid[i][j + 1] == c &&
                   s.find(grid[i][j]) == s.end()) {
          ans++;
          s.insert(grid[i][j]);
        } else if (j - 1 >= 0 && grid[i][j - 1] == c &&
                   s.find(grid[i][j]) == s.end()) {
          ans++;
          s.insert(grid[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
