text: #include <stdio.h>
  
  #include <algorithm>
  #include <array>
  #include <bitset>
  #include <cassert>
  #include <climits>
  #include <cmath>
  #include <deque>
  #include <fstream>
  #include <functional>
  #include <iomanip>
  #include <iostream>
  #include <iterator>
  #include <list>
  #include <map>
  #include <numeric>
  #include <queue>
  #include <set>
  #include <sstream>
  #include <stack>
  #include <string>
  #include <unordered_map>
  #include <unordered_set>
  #include <vector>
  
  using namespace std;
  
  #ifndef ONLINE_JUDGE
  #define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", _debug(__VA_ARGS__)
  #else
  #define debug(...) 0
  #endif
  
  string to_string(string s) { return '"' + s + '"'; }
  string to_string(const char *s) { return to_string((string)s); }
  string to_string(bool b) { return (b ? "true" : "false"); }
  template <typename A, typename B>
  string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
  }
  template <typename A, typename B, typename C>
  string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
           to_string(get<2>(t)) + ")";
  }
  template <typename A>
  string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
      if (!first) {
        res += ", ";
      }
      first = false;
      res += to_string(x);
    }
    res += '}';
    return res;
  }
  
  void _debug() { cerr << '\n'; }
  template <typename Head, typename... Tail>
  void _debug(Head H, Tail... T) {
    cerr << ' ' << to_string(H);
    _debug(T...);
  }
  
  #define eb emplace_back
  
  using ll = long long;
  using ld = long double;
  using ii = pair<int, int>;
  using vi = vector<int>;
  using vii = vector<ii>;
  using vc = vector<char>;
  using vb = vector<bool>;
  using vll = vector<ll>;
  
  int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(9);
  
  #ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
    freopen("./output.txt", "w", stdout);
  #endif
  
    int n, m;
    char c;
    cin >> n >> m >> c;
  
    vii locs;
    vector<vc> grid(n, vc(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> grid[i][j];
        if (grid[i][j] == c) {
          locs.emplace_back(i, j);
        }
      }
    }
  
    int cnt = 0;
    vb seen(256);
    for (auto &[r, c] : locs) {
      for (int dr = -1; dr <= 1; ++dr) {
        int nr = dr + r;
        if (nr < 0 || nr >= n) continue;
        for (int dc = -1; dc <= 1; ++dc) {
          int nc = dc + c;
          if (!dc && !dr) continue;
          if (dr && dc) continue;
          if (nc < 0 || nc >= m) continue;
          if (grid[nr][nc] == '.') continue;
          if (!seen[grid[nr][nc]]) {
            ++cnt;
            seen[grid[nr][nc]] = 1;
          }
        }
      }
    }
  
    cout << cnt - seen[c];
  }
  