#include <bits/stdc++.h>
using namespace std;
int main() {
  int dx[4] = {0, 0, -1, 1};
  int dy[4] = {-1, 1, 0, 0};
  register int x, y;
  char s[100 + 10][100 + 10];
  map<char, int> mp;
  int n, m;
  char ch;
  while (cin >> n >> m >> ch) {
    for (register int i = 0; i < n; ++i) cin >> s[i];
    register int ans = 0;
    for (register int i = 0; i < n; ++i)
      for (register int j = 0; j < m; ++j)
        if (s[i][j] == ch)
          for (register int k = 0; k < 4; ++k) {
            x = i + dx[k], y = j + dy[k];
            if (s[x][y] == ch || s[x][y] == '.' || mp[s[x][y]] || x < 0 ||
                x >= n || y < 0 || y >= m)
              continue;
            ans++;
            mp[s[x][y]]++;
          }
    cout << ans << endl;
  }
  return 0;
}
