#include <bits/stdc++.h>
using namespace std;
map<char, int> H;
char s[120][120];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ans;
int main() {
  int n, m;
  char c;
  cin >> n >> m >> c;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == c)
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (x <= 0 || x > n) continue;
          if (y <= 0 || y > m) continue;
          if (s[x][y] == c) continue;
          if (s[x][y] == '.') continue;
          if (H[s[x][y]]) continue;
          ans++;
          H[s[x][y]]++;
        }
    }
  }
  cout << ans << endl;
}
