#include <bits/stdc++.h>
using namespace std;
char area[108][108];
unordered_set<char> zams;
int main() {
  for (int i = 0; i < 108; ++i)
    for (int j = 0; j < 108; ++j) area[i][j] = '.';
  int n, m;
  int pnl = -1, pml = -1, pnr = -1, pmr = -1;
  char p, c;
  cin >> n >> m >> p;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> c;
      area[i + 2][j + 2] = c;
      if (c == p) {
        if (pnl == -1) {
          pnl = pnr = i;
          pml = pmr = j;
        } else {
          pnr = i;
          pmr = j;
        }
      }
    }
  for (int i = pnl; i <= pnr; ++i) {
    char c1 = area[i + 2][pml + 1];
    char c2 = area[i + 2][pmr + 3];
    if (c1 != '.') zams.insert(c1);
    if (c2 != '.') zams.insert(c2);
  }
  for (int j = pml; j <= pmr; ++j) {
    char c1 = area[pnl + 1][j + 2];
    char c2 = area[pnr + 3][j + 2];
    if (c1 != '.') zams.insert(c1);
    if (c2 != '.') zams.insert(c2);
  }
  cout << zams.size() << endl;
  return 0;
}
