#include <bits/stdc++.h>
using namespace std;
void file() { freopen("divisors.in", "r", stdin); }
const int maxsize = 1e2 + 5, oo = 0X3f3f3f3f;
int n, m, tot, arr[7], freq[11];
int maxx;
vector<long long> v;
map<string, string> mp;
char s[maxsize][maxsize];
char c;
bool valid(int x, int y) { return x > -1 && x < n && y > -1 && y < m; }
int dirx[] = {-1, 0, 1, 0};
int diry[] = {0, 1, 0, -1};
set<char> ans;
int main() {
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> s[i][j];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == c) {
        for (int z = 0; z < 4; z++) {
          int x = i + dirx[z];
          int y = j + diry[z];
          if (valid(x, y) && s[x][y] != c && s[x][y] != '.')
            ans.insert(s[x][y]);
        }
      }
    }
  cout << ans.size() << '\n';
  return 0;
}
