#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, count = 0;
  char c;
  set<char> st;
  char a[100][100];
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if ((a[i][j] != c) &&
          (((i > 0) && (a[i - 1][j] == c)) ||
           ((j > 0) && (a[i][j - 1] == c))) &&
          (st.find(a[i][j]) == st.end() && (a[i][j] != '.'))) {
        st.insert(a[i][j]);
        count++;
      }
      if (a[i][j] == c) {
        if ((i > 0) && (a[i - 1][j] != c) &&
            (st.find(a[i - 1][j]) == st.end()) && (a[i - 1][j] != '.')) {
          st.insert(a[i - 1][j]);
          count++;
        }
        if ((j > 0) && (a[i][j - 1] != c) &&
            (st.find(a[i][j - 1]) == st.end()) && (a[i][j - 1] != '.')) {
          st.insert(a[i][j - 1]);
          count++;
        }
      }
    }
  cout << count;
}
