#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  char c;
  cin >> c;
  char arr[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  long long check[26];
  for (long long i = 0; i < 26; i++) {
    check[i] = 1;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == c) {
        if (j + 1 < m) {
          if (arr[i][j + 1] >= 65 && arr[i][j + 1] <= 90) {
            if (arr[i][j + 1] != c) {
              long long checker = arr[i][j + 1] - 'A';
              if (check[checker] == 1) {
                check[checker] = 0;
                ans++;
              } else {
                ans += 0;
              }
            }
          }
        }
        if (j - 1 >= 0) {
          if (arr[i][j - 1] >= 65 && arr[i][j - 1] <= 90) {
            if (arr[i][j - 1] != c) {
              long long checker = arr[i][j - 1] - 'A';
              if (check[checker] == 1) {
                check[checker] = 0;
                ans++;
              } else {
                ans += 0;
              }
            }
          }
        }
        if (i + 1 < n) {
          if (arr[i + 1][j] >= 65 && arr[i + 1][j] <= 90) {
            if (arr[i + 1][j] != c) {
              long long checker = arr[i + 1][j] - 'A';
              if (check[checker] == 1) {
                check[checker] = 0;
                ans++;
              } else {
                ans += 0;
              }
            }
          }
        }
        if (i - 1 >= 0) {
          if (arr[i - 1][j] >= 65 && arr[i - 1][j] <= 90) {
            if (arr[i - 1][j] != c) {
              long long checker = arr[i - 1][j] - 'A';
              if (check[checker] == 1) {
                check[checker] = 0;
                ans++;
              } else {
                ans += 0;
              }
            }
          }
        }
      }
    }
  }
  cout << ans;
}
