#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  char p;
  cin >> n >> m >> p;
  string s[n];
  char ch[n][m];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) ch[i][j] = s[i][j];
  }
  int count = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (ch[i][j] == p) {
        if (i - 1 >= 0 && ch[i - 1][j] != '.' && ch[i - 1][j] != p) {
          count++;
          char temp = ch[i - 1][j];
          for (int k = 0; k < n; k++)
            for (int l = 0; l < m; l++)
              if (temp == ch[k][l]) ch[k][l] = '.';
        }
        if (j - 1 >= 0 && ch[i][j - 1] != '.' && ch[i][j - 1] != p) {
          char temp = ch[i][j - 1];
          for (int k = 0; k < n; k++)
            for (int l = 0; l < m; l++)
              if (temp == ch[k][l]) ch[k][l] = '.';
          count++;
        }
        if (i + 1 < n && ch[i + 1][j] != '.' && ch[i + 1][j] != p) {
          char temp = ch[i + 1][j];
          for (int k = 0; k < n; k++)
            for (int l = 0; l < m; l++)
              if (temp == ch[k][l]) ch[k][l] = '.';
          count++;
        }
        if (j + 1 < m && ch[i][j + 1] != '.' && ch[i][j + 1] != p) {
          char temp = ch[i][j + 1];
          for (int k = 0; k < n; k++)
            for (int l = 0; l < m; l++)
              if (temp == ch[k][l]) ch[k][l] = '.';
          count++;
        }
      }
  cout << count << endl;
  return 0;
}
