#include <stdio.h>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
const int MAXN = 105;
char matrix[MAXN][MAXN];
bool Hash[256];
void Find(int x, int y)
{
if(isupper(matrix[x][y - 1]))
Hash[matrix[x][y - 1]] = true;
if(isupper(matrix[x][y + 1]))
Hash[matrix[x][y + 1]] = true;
if(isupper(matrix[x - 1][y]))
Hash[matrix[x - 1][y]] = true;
if(isupper(matrix[x + 1][y]))
Hash[matrix[x + 1][y]] = true;
}
int main()
{
#ifdef _LOCAL
freopen("F://input.txt", "r", stdin);
#endif
int n, m, posX, posY;
char ch;
scanf("%d%d %c", &n, &m, &ch);
vector<pair<int, int>> president;
Hash[ch] = true;
for(int i = 1; i <= n; ++i)
{
getchar();
for(int j = 1; j <= m; ++j)
{
scanf("%c", &matrix[i][j]);
if(matrix[i][j] == ch)
president.push_back(make_pair(i, j));
}
}
for(int i = 0; i < president.size(); ++i)
Find(president[i].first, president[i].second);
int count = 0;
for(int i = 'A'; i <= 'Z'; ++i)
if(Hash[i]) ++count;
printf("%d\n", count - 1);
return 0;
}