#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long inf = 3e18;
const long long N = 5e5 + 5;
long long n, m;
char boss;
char mat[102][102];
long long vis[102][102];
long long rr[] = {0, 1, 0, -1};
long long cc[] = {1, 0, -1, 0};
map<pair<long long, long long>, bool> table;
set<char> ans;
bool inside(long long x, long long y) {
  return (x >= 1 && x <= n && y >= 1 && y <= m);
}
void dfs(long long x, long long y) {
  if (!inside(x, y)) return;
  if (mat[x][y] != boss) return;
  if (vis[x][y]) return;
  vis[x][y] = true;
  table[{x, y}] = true;
  for (long long i = 0; i < 4; i++) {
    long long xd = rr[i] + x;
    long long yd = cc[i] + y;
    dfs(xd, yd);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> boss;
  for (long long i = 1; i <= (n); i++)
    for (long long j = 1; j <= (m); j++) cin >> mat[i][j];
  for (long long i = 1; i <= (n); i++) {
    for (long long j = 1; j <= (m); j++) {
      if (mat[i][j] == boss) {
        if (!vis[i][j]) dfs(i, j);
      }
    }
  }
  for (auto it : table) {
    long long x = it.first.first, y = it.first.second;
    for (long long i = 0; i < 4; i++) {
      long long xd = x + rr[i], yd = y + cc[i];
      if (inside(xd, yd) and (mat[xd][yd] != boss) and (mat[xd][yd] != '.')) {
        ans.insert(mat[xd][yd]);
      }
    }
  }
  if (ans.count(boss)) ans.erase(ans.find(boss));
  cout << ((long long)(ans.size())) << '\n';
}
