#include <bits/stdc++.h>
using namespace std;
char room[100][100];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
void solve() {
  int n, m;
  char boss;
  cin >> n >> m >> boss;
  set<char> ans;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> room[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (room[i][j] == boss)
        for (int k = 0; k < 4; ++k)
          if (j + dx[k] >= 0 && j + dx[k] < m && i + dy[k] >= 0 &&
              i + dy[k] < n && room[i + dy[k]][j + dx[k]] != '.' &&
              room[i + dy[k]][j + dx[k]] != boss)
            ans.insert(room[i + dy[k]][j + dx[k]]);
  cout << ans.size() << endl;
}
int main() {
  solve();
  return 0;
}
