#include<set>
#include<iostream>
using namespace std;
char str[101][101]={'.'};
int main()
{
    int n,m;
    char c;
    cin>>n>>m>>c;
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) cin>>str[i][j];
    set <char> ok;
    int s[26]={0};
    int result=0;
    for (int i=2;i<n;i++)
        for (int j=2;j<m;j++)
            if (str[i][j]==c){
                s[str[i-1][j]-'A']++;
                s[str[i+1][j]-'A']++;
                s[str[i][j+1]-'A']++;
                s[str[i][j-1]-'A']++;
            }
    for (int i=0;i<26;i++) result+=s[i];
    if (s[c-'A']>0) result-=s[c-'A'];
    result--;
    cout<<result<<"\n";
    //system("pause");
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

void check(char board[101][101], int row, int collumn, int i, int j, bool* table, int* count)
{
	if (i+1 <= row && board[i+1][j] != '.' && !table[board[i+1][j] -'A'])
	{
		table[board[i+1][j] -'A'] = true;
		(*count)++;
	}

	if (j+1 <= collumn && board[i][j+1] != '.' && !table[board[i][j+1] -'A'])
	{
		table[board[i][j+1] -'A'] = true;
		(*count)++;
	}

	if (i-1 >= 1 && board[i-1][j] != '.' && !table[board[i-1][j] -'A'])
	{
		table[board[i-1][j] -'A'] = true;
		(*count)++;
	}

	if (j-1 >= 1 && board[i][j-1] != '.' && !table[board[i][j-1] -'A'])
	{
		table[board[i][j-1] -'A'] = true;
		(*count)++;
	}

}

int main()
{

	freopen("C:\\Users\\Fnac\\Desktop\\Rodrigo\\ITA\\Contest\\codeForces\\entrada.txt","r" , stdin);
	freopen("C:\\Users\\Fnac\\Desktop\\Rodrigo\\ITA\\Contest\\codeForces\\saida.txt","w",stdout);

	int row,collumn;
	int count = 0;
	char presidentCollor;
	char board[101][101];
	bool table['Z' - ('A' -1)];

	cin >> row >> collumn >> presidentCollor;

	for (int i = 'A'; i <= 'Z'; i++) table[ i - 'A'] = false;
	table[presidentCollor - 'A'] = true;

	for (int i = 1; i <= row; i++)
	{
		for (int j = 1; j <= collumn; j++)
		{
			cin  >> board[i][j];
		}
	}

	for (int i = 1; i <= row; i++)
	{
		for (int j = 1; j <= collumn; j++)
		{
			if(board[i][j] == presidentCollor)
			{
				check(board, row, collumn, i, j, table, &count);
			}
		}
	}

	cout << count;

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

void check(char board[101][101], int row, int collumn, int i, int j, bool* table, int* count)
{
	if (i+1 <= row && board[i+1][j] != '.' && !table[board[i+1][j] -'A'])
	{
		table[board[i+1][j] -'A'] = true;
		(*count)++;
	}

	if (j+1 <= collumn && board[i][j+1] != '.' && !table[board[i][j+1] -'A'])
	{
		table[board[i][j+1] -'A'] = true;
		(*count)++;
	}

	if (i-1 >= 1 && board[i-1][j] != '.' && !table[board[i-1][j] -'A'])
	{
		table[board[i-1][j] -'A'] = true;
		(*count)++;
	}

	if (j-1 >= 1 && board[i][j-1] != '.' && !table[board[i][j-1] -'A'])
	{
		table[board[i][j-1] -'A'] = true;
		(*count)++;
	}

}

int main()
{

	//freopen("C:\\Users\\Fnac\\Desktop\\Rodrigo\\ITA\\Contest\\codeForces\\entrada.txt","r" , stdin);
	//freopen("C:\\Users\\Fnac\\Desktop\\Rodrigo\\ITA\\Contest\\codeForces\\saida.txt","w",stdout);

	int row,collumn;
	int count = 0;
	char presidentCollor;
	char board[101][101];
	bool table['Z' - ('A' -1)];

	cin >> row >> collumn >> presidentCollor;

	for (int i = 'A'; i <= 'Z'; i++) table[ i - 'A'] = false;
	table[presidentCollor - 'A'] = true;

	for (int i = 1; i <= row; i++)
	{
		for (int j = 1; j <= collumn; j++)
		{
			cin  >> board[i][j];
		}
	}

	for (int i = 1; i <= row; i++)
	{
		for (int j = 1; j <= collumn; j++)
		{
			if(board[i][j] == presidentCollor)
			{
				check(board, row, collumn, i, j, table, &count);
			}
		}
	}

	cout << count;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <math.h>
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(n);++i)
int N,M;
char c;
map<char,int>m;
string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
    for(int i=0;i<26;++i){
        m[alphabet[i]]=i+1;
    }
    cin>>N>>M>>c;
    int a[100][100];
    for(int i=0;i<N;++i){
        string s = "";
        cin>>s;
        for(int j=0;j<M;++j){
            if(s[i]!='.')a[i][j]=m[s[j]];
        }
    }
    int cnt = 0;
    map<int,int>deputy;
    REP(i,N)REP(j,N){
        if(a[i][j]==m[c]){
        if(i-1>=0){
            if(a[i-1][j]!=m[c]&&deputy[a[i-1][j]]==0&&a[i-1][j]!=0){
                cnt++;
                deputy[a[i-1][j]]++;
            }
        }
        if(i+1<N){
            if(a[i+1][j]!=m[c]&&deputy[a[i+1][j]]==0&&a[i+1][j]!=0){
                cnt++;
                deputy[a[i+1][j]]++;
            }

        }
        if(j-1>=0)
        {
            if(a[i][j-1]!=m[c]&&deputy[a[i][j-1]]==0&&a[i][j-1]!=0){
                cnt++;
                deputy[a[i][j-1]]++;
            }
        }
        if(j+1<N)
        {
            if(a[i][j+1]!=m[c]&&deputy[a[i][j+1]]==0&&a[i][j+1]!=0){
                cnt++;
                deputy[a[i][j+1]]++;
            }
        }
    }
    }
    cout<<cnt<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <math.h>
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(n);++i)
int N,M;
char c;
map<char,int>m;
string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
    for(int i=0;i<26;++i){
        m[alphabet[i]]=i;
    }
    cin>>N>>M>>c;
    int a[100][100];
    for(int i=0;i<N;++i){
        string s = "";
        cin>>s;
        for(int j=0;j<M;++j){
            if(s[i]=='.')a[i][j]=99999;
            else a[i][j]=m[s[j]];
        }
    }
    int cnt = 0;
    map<int,int>deputy;
    REP(i,N)REP(j,N){
        if(a[i][j]==m[c]){
        if(i-1>=0){
            if(a[i-1][j]!=m[c]&&deputy[a[i-1][j]]==0){
                cnt++;
                deputy[a[i-1][j]]++;
            }
        }
        if(i+1<N){
            if(a[i+1][j]!=m[c]&&deputy[a[i+1][j]]==0){
                cnt++;
                deputy[a[i+1][j]]++;
            }

        }
        if(j-1>=0)
        {
            if(a[i][j-1]!=m[c]&&deputy[a[i][j-1]]==0){
                cnt++;
                deputy[a[i][j-1]]++;
            }
        }
        if(j+1<N)
        {
            if(a[i][j+1]!=m[c]&&deputy[a[i][j+1]]==0){
                cnt++;
                deputy[a[i][j+1]]++;
            }
        }
    }
    }
    cout<<cnt-1<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <math.h>
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(n);++i)
int N,M;
char c;
map<char,int>m;
string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
    for(int i=0;i<26;++i)m[alphabet[i]]=i+1;
    cin>>N>>M>>c;
    int a[100][100];
    REP(i,N)REP(j,N)a[i][j]=0;
    for(int i=0;i<N;++i){
        string s = "";
        cin>>s;
        for(int j=0;j<M;++j)if(s[j]!='.')a[i][j]=m[s[j]];
    }
    int cnt = 0;
    map<int,int>deputy;
    for(int i=0;i<N;++i)for(int j=0;j<M;++j){
        if(a[i][j]==m[c]){
        if(i-1>=0){
            if(a[i-1][j]!=m[c]&&deputy[a[i-1][j]]==0&&a[i-1][j]!=0){
                cnt++;
                deputy[a[i-1][j]]++;
            }
        }
        if(i+1<N){
            if(a[i+1][j]!=m[c]&&deputy[a[i+1][j]]==0&&a[i+1][j]!=0){
                cnt++;
                deputy[a[i+1][j]]++;
            }

        }
        if(j-1>=0)
        {
            if(a[i][j-1]!=m[c]&&deputy[a[i][j-1]]==0&&a[i][j-1]!=0){
                cnt++;
                deputy[a[i][j-1]]++;
            }
        }
        if(j+1<N)
        {
            if(a[i][j+1]!=m[c]&&deputy[a[i][j+1]]==0&&a[i][j+1]!=0){
                cnt++;
                deputy[a[i][j+1]]++;
            }
        }
    }
    }
    cout<<cnt<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <math.h>
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(n);++i)
int N,M;
char c;
map<char,int>m;
string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
    for(int i=0;i<26;++i)m[alphabet[i]]=i+1;
    cin>>N>>M>>c;
    int a[100][100];
    REP(i,N)REP(j,N)a[i][j]=0;
    for(int i=0;i<N;++i){
        string s = "";
        cin>>s;
        for(int j=0;j<M;++j)if(s[j]!='.')a[i][j]=m[s[j]];
    }
    int cnt = 0;
    map<int,int>deputy;
    for(int i=0;i<N;++i)for(int j=0;j<M;++j){
        if(a[i][j]==m[c]){
        if(i-1>=0){
            if(a[i-1][j]!=m[c]&&deputy[a[i-1][j]]==0&&a[i-1][j]!=0){
                cnt++;
                deputy[a[i-1][j]]++;
            }
        }
        if(i+1<N){
            if(a[i+1][j]!=m[c]&&deputy[a[i+1][j]]==0&&a[i+1][j]!=0){
                cnt++;
                deputy[a[i+1][j]]++;
            }

        }
        if(j-1>=0)
        {
            if(a[i][j-1]!=m[c]&&deputy[a[i][j-1]]==0&&a[i][j-1]!=0){
                cnt++;
                deputy[a[i][j-1]]++;
            }
        }
        if(j+1<M)
        {
            if(a[i][j+1]!=m[c]&&deputy[a[i][j+1]]==0&&a[i][j+1]!=0){
                cnt++;
                deputy[a[i][j+1]]++;
            }
        }
    }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<set>
using namespace std;

int main()
{
	char matr[102][102];
	int n, m, i0, j0, i1, j1, flag=0;
	char PC;
	cin>>n>>m>>PC;
	for(int i=1; i<=n; i++)
		for(int j=1;j<=m; j++)
		{
			cin>>matr[i][j];
			if(flag==0 && matr[i][j]==PC)
			{
				i0=i;j0=j;flag=1;
			}
			else if(flag==1)
			{
				i1=i; j1=j;
				if(matr[i][j]!=PC) flag=2;
			}

		}

	for(int j=1; j<m; j++)
	{
		matr[0][j]='.';
		matr[n+1][j]='.';
	}

	for(int i=1; i<n; i++)
	{
		matr[i][0]='.';
		matr[i][m+1]='.';
	}

	set<char> s;
	for (int j=j0; j<=j1; j++)
	{
		s.insert(matr[i0-1][j]);
		s.insert(matr[i1+1][j]);
	}
	for (int i=i0; i<=i1; i++)
	{
		s.insert(matr[i][j0-1]);
		s.insert(matr[i][j1+1]);
	}
	cout<<s.size();
	return 0;

}


#include<iostream>
#include<set>
using namespace std;

int main()
{
	char matr[102][102];
	int n, m, i0, j0, i1, j1, flag=0;
	char PC;
	cin>>n>>m>>PC;
	for(int i=1; i<=n; i++)
		for(int j=1;j<=m; j++)
		{
			cin>>matr[i][j];
			if(flag==0 && matr[i][j]==PC)
			{
				i0=i;j0=j;flag=1;
			}
			else if(flag==1)
			{
				i1=i; j1=j;
				if(matr[i][j]!=PC) flag=2;
			}

		}

	for(int j=1; j<=m; j++)
	{
		matr[0][j]='.';
		matr[n+1][j]='.';
	}

	for(int i=1; i<=n; i++)
	{
		matr[i][0]='.';
		matr[i][m+1]='.';
	}

	set<char> s;
	for (int j=j0; j<=j1; j++)
	{
		s.insert(matr[i0-1][j]);
		s.insert(matr[i1+1][j]);
	}
	for (int i=i0; i<=i1; i++)
	{
		s.insert(matr[i][j0-1]);
		s.insert(matr[i][j1+1]);
	}
	if(s.count('.'))cout<<s.size()-1;
	else cout<<s.size();
	return 0;

}


#include<iostream>
#include<set>
using namespace std;

int main()
{
	char matr[102][102];
	int n, m, i0, j0, i1, j1, flag=0;
	char PC;
	cin>>n>>m>>PC;
	for(int i=1; i<=n; i++)
		for(int j=1;j<=m; j++)
		{
			cin>>matr[i][j];
			if(flag==0 && matr[i][j]==PC)
			{
				i0=i;j0=j;flag=1;
			}
		}

	int i=n;  flag=1;
	while(flag && i)
	{
		int j=m;
		while(j && matr[i][j]!=PC) j--;
		if(j)
		{
			i1=i; j1=j; flag=0;
		}
		i--;
	}
	if(i==0)
	{
		i1=j1=1;
	}

	for(int j=1; j<=m; j++)
	{
		matr[0][j]=matr[n+1][j]='.';
	}

	for(int i=1; i<=n; i++)
	{
		matr[i][0]=matr[i][m+1]='.';
	}
/*
	for(int i=0; i<=n+1; i++)
	{
		for(int j=0; j<=m+1; j++)
			cout<<matr[i][j];
		cout<<endl;
	}
*/
	set<char> s; s.insert('.');
	int k(0);
	for (int j=j0; j<=j1; j++)
	{
		if(s.insert(matr[i0-1][j]).second)k++;
		if(s.insert(matr[i1+1][j]).second)k++;
	}
	for (int i=i0; i<=i1; i++)
	{
		if(s.insert(matr[i][j0-1]).second)k++;
		if(s.insert(matr[i][j1+1]).second)k++;
	}
	/*
	if(s.count('.'))cout<<s.size()-1;
	else cout<<s.size();
	*/
	cout<<k;
	return 0;

}


#include<iostream>
#include<set>
using namespace std;

int main()
{
	char matr[102][102];
	int n, m, i0, j0, i1, j1, flag=0;
	char PC;
	cin>>n>>m>>PC;
	for(int i=1; i<=n; i++)
		for(int j=1;j<=m; j++)
		{
			cin>>matr[i][j];
			if(flag==0 && matr[i][j]==PC)
			{
				i0=i;j0=j;flag=1;
			}
			else if(flag==1)
			{
				if(matr[i][j]==PC) {i1=i; j1=j;}
			}
		}

	for(int j=1; j<=m; j++)
	{
		matr[0][j]=matr[n+1][j]='.';
	}

	for(int i=1; i<=n; i++)
	{
		matr[i][0]=matr[i][m+1]='.';
	}
/*
	for(int i=0; i<=n+1; i++)
	{
		for(int j=0; j<=m+1; j++)
			cout<<matr[i][j];
		cout<<endl;
	}
*/
	set<char> s; s.insert('.');
	int k(0);
	for (int j=j0; j<=j1; j++)
	{
		if(s.insert(matr[i0-1][j]).second)k++;
		if(s.insert(matr[i1+1][j]).second)k++;
	}
	for (int i=i0; i<=i1; i++)
	{
		if(s.insert(matr[i][j0-1]).second)k++;
		if(s.insert(matr[i][j1+1]).second)k++;
	}
	/*
	if(s.count('.'))cout<<s.size()-1;
	else cout<<s.size();
	*/
	cout<<k;
	return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.first=s[i].find(x))!=string::npos)
        {
            p.second=s[i].rfind(x);
            //ff(it,s[i]) M[*it]++;
            break;
        }
    }

    f0(i,n)
    {
        ffor(j,p.first,p.second+1)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m,y;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.first=s[i].find(x))!=string::npos)
        {
            p.second=s[i].rfind(x);
            M[s[i][max(0,p.first-1)]]++;
            M[s[i][min(0,p.second+1)]]++;
            y=i;
            break;
        }
    }

    ffor(i,max(0,y-1),min(n,y+1))
    {
        ffor(j,p.first,p.second+1)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m,w,h=0;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.second=s[i].find(x))!=string::npos)
        {
            h++;
            p.first=i;
            w=s[i].rfind(x)-p.second+1;

            ffor(j,i+1,n)
            {
                if (s[j][p.second]==x)
                {
                    h++;
                    continue;
                }
                break;
            }
            break;
        }
    }

    ffor(i,p.first,p.first+h)
    {
        M[s[i][max(0,p.second-1)]]++;
        M[s[i][min(m-1,p.second+w)]]++;
    }

    ffor(i, max(0,p.first-1), min(n,p.first+h+1))
    {
        ffor(j,p.second,p.second+w)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m,y;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.first=s[i].find(x))!=string::npos)
        {
            p.second=s[i].rfind(x);
            M[s[i][max(0,p.first-1)]]++;
            M[s[i][min(m-1,p.second+1)]]++;
            y=i;
            break;
        }
    }

    ffor(i,max(0,y-1),min(n,y+2))
    {
        ffor(j,p.first,p.second+1)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m,y;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.first=s[i].find(x))!=string::npos)
        {
            p.second=s[i].rfind(x);
            M[s[i][max(0,p.first-1)]]++;
            M[s[i][min(0,p.second+1)]]++;
            y=i;
            break;
        }
    }

    ffor(i,max(0,y-1),min(n,y+2))
    {
        ffor(j,p.first,p.second+1)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.first=s[i].find(x))!=string::npos)
        {
            p.second=s[i].rfind(x);
            ff(it,s[i]) M[*it]++;
            break;
        }
    }

    f0(i,n)
    {
        ffor(j,p.first,p.second+1)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
//#include <stack>
#include <map>
//#include <unordered_set>
using namespace std;
#define ff(i,m) for(auto i=m.begin();i!=m.end();i++)
#define fr(i,m) for(auto i=m.rbegin();i!=m.rend();i++)
#define f0(i,n) for(decltype(n) i=0;i<n;i++)
#define f1(i,n) for(decltype(n) i=1;i<n;i++)
#define ffor(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef pair<int,int> P;
int getint();

string s[100];

void main()
{
    P p;
    char x;
    int n,m,w,h=0;
    map<char,int> M;

    cin>>n>>m>>x;
    f0(i,n) cin>>s[i];
    f0(i,n)
    {
        if ((p.second=s[i].find(x))!=string::npos)
        {
            h++;
            p.first=i;
            w=s[i].rfind(x)-p.second+1;

            ffor(j,i+1,n)
            {
                if (s[j][p.second]==x)
                {
                    h++;
                    continue;
                }
                break;
            }
            break;
        }
    }

    ffor(i,p.first,p.first+h)
    {
        M[s[i][max(0,p.second-1)]]++;
        M[s[i][min(m-1,p.second+w)]]++;
    }

    ffor(i, max(0,p.second-1), min(n,p.second+h+1))
    {
        ffor(j,p.second,p.second+w)
        {
            M[s[i][j]]++;
        }
    }

    M.erase('.'); M.erase(x);
    cout<<M.size()<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <bitset>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;
#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define REPV(i, n) for (int i = (n) - 1; (int)i >= 0; --i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORV(i, a, b) for(int i = (int)(a)-1; i >= (int)(b); --i)
#define FORE(i, a) for(int i = 0; i < (int)a.size(); ++i)

#define two(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define sz(a) (int)a.size()
#define shows(a) if(a++)cout<<endl
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x, y)
#define println(a) cout<<a<<endl
#define print(a) cout<<a
#define clr(a,b) memset(a,b,sizeof(a))
#define OO 1e8
#define EPS 1e-6
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<ull> vull;

template<class T> void checkmin(T &a, T b){ if (b<a)a = b; }
template<class T> void checkmax(T &a, T b){ if (b>a)a = b; }
template<class T> void out(T t[], int n){ REP(i, n)cout << t[i] << " "; cout << endl; }
template<class T> void out(vector<T> t, int n = -1){ for (int i = 0; i<(n == -1 ? t.size() : n); ++i) cout << t[i] << " "; cout << endl; }
inline int count_bit(int n){ return (n == 0) ? 0 : 1 + count_bit(n&(n - 1)); }
inline int low_bit(int n){ return (n^n - 1)&n; }
inline int ctz(int n){ return (n == 0 ? 0 : ctz(n >> 1) + 1); }
int toInt(string s){ int a; istringstream(s) >> a; return a; }
string toStr(int a){ ostringstream os; os << a; return os.str(); }
string reverse(string& s){ int n = s.size(); REP(i, n / 2) s[i] = s[n - 1 - i]; return s; }
inline int isvalid(int i, int j, int H, int L){ return (i >= H || i<0 || j >= L || j<0) ? 0 : 1; }
inline int doubleComare(double x, double y){ if (fabs(x - y) <= EPS) return 0; if (x<y) return -1; return 1; }

void main()
{
    //ifstream cin("a.in");
    int n, m;

    char p;
    cin >> n >> m >> p;
    vs v(n);
    set<char> s;
    REP(i, n)cin >> v[i];
    REP(i, n)REP(j, m) if (v[i][j] == p) {
        if (isvalid(i - 1, j, n, m) && v[i - 1][j] != p&& v[i - 1][j] != '.') s.insert(v[i - 1][j]);
        else if (isvalid(i + 1, j, n, m) && v[i + 1][j] != p&& v[i + 1][j] != '.') s.insert(v[i +1][j]);
        else if (isvalid(i, j-1, n, m) && v[i][j-1] != p&& v[i][j-1] != '.') s.insert(v[i][j-1]);
        else if (isvalid(i, j+1, n, m) && v[i][j+1] != p&& v[i][j+1] != '.') s.insert(v[i][j+1]);
    }
    cout << s.size() << endl;
   // system("pause");
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <bitset>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;
#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define REPV(i, n) for (int i = (n) - 1; (int)i >= 0; --i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORV(i, a, b) for(int i = (int)(a)-1; i >= (int)(b); --i)
#define FORE(i, a) for(int i = 0; i < (int)a.size(); ++i)

#define two(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define sz(a) (int)a.size()
#define shows(a) if(a++)cout<<endl
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x, y)
#define println(a) cout<<a<<endl
#define print(a) cout<<a
#define clr(a,b) memset(a,b,sizeof(a))
#define OO 1e8
#define EPS 1e-6
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<ull> vull;

template<class T> void checkmin(T &a, T b){ if (b<a)a = b; }
template<class T> void checkmax(T &a, T b){ if (b>a)a = b; }
template<class T> void out(T t[], int n){ REP(i, n)cout << t[i] << " "; cout << endl; }
template<class T> void out(vector<T> t, int n = -1){ for (int i = 0; i<(n == -1 ? t.size() : n); ++i) cout << t[i] << " "; cout << endl; }
inline int count_bit(int n){ return (n == 0) ? 0 : 1 + count_bit(n&(n - 1)); }
inline int low_bit(int n){ return (n^n - 1)&n; }
inline int ctz(int n){ return (n == 0 ? 0 : ctz(n >> 1) + 1); }
int toInt(string s){ int a; istringstream(s) >> a; return a; }
string toStr(int a){ ostringstream os; os << a; return os.str(); }
string reverse(string& s){ int n = s.size(); REP(i, n / 2) s[i] = s[n - 1 - i]; return s; }
inline int isvalid(int i, int j, int H, int L){ return (i >= H || i<0 || j >= L || j<0) ? 0 : 1; }
inline int doubleComare(double x, double y){ if (fabs(x - y) <= EPS) return 0; if (x<y) return -1; return 1; }

void main()
{
    //ifstream cin("a.in");
    int n, m;

    char p;
    cin >> n >> m >> p;
    vs v(n);
    set<char> s;
    REP(i, n)cin >> v[i];
    REP(i, n)REP(j, m) if (v[i][j] == p) {
        //cout << i << j;
        if (isvalid(i - 1, j, n, m) && v[i-1][j] != p   && v[i-1][j] != '.') s.insert(v[i - 1][j]);
         if (isvalid(i+1, j, n, m) && v[i+1][j] != p&& v[i+1][j] != '.') s.insert(v[i +1][j]);
         if (isvalid(i, j-1, n, m) && v[i][j-1] != p&& v[i][j-1] != '.') s.insert(v[i][j-1]);
         if (isvalid(i, j+1, n, m) && v[i][j+1] != p&& v[i][j+1] != '.') s.insert(v[i][j+1]);
    }
    cout <<s.size() << endl;
    //system("pause");
}


#include <iostream>
#include <algorithm>
#include <list>
using namespace std;

int main()
{
	int n, m;
	char K;
	cin >> n >> m >> K;
	n += 2;
	m += 2;
	char** mas = new char*[n];
	for (int i = 0; i < n; i++)
		mas[i] = new char[m];
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			mas[i][j] = '0';
		}
	}
	for (int i = 1; i < n-1; i++){
		for (int j = 1; j < m-1; j++){
			cin >> mas[i][j];
		}
	}
	list<char> a;
	a.push_front('.');
	a.push_front('0');
	a.push_front(K);
	int l = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (mas[i][j] == K){
				/*if (mas[i - 1][j] != '.' && mas[i - 1][j] != K && mas[i - 1][j] != '0' && find(a.begin(), a.end(), mas[i - 1][j]) == a.end()) { l++; a.push_back(mas[i - 1][j]); }
				if (mas[i + 1][j] != '.' && mas[i + 1][j] != K && mas[i + 1][j] != '0' && find(a.begin(), a.end(), mas[i + 1][j]) == a.end()) { l++; a.push_back(mas[i + 1][j]); }
				if (mas[i][j - 1] != '.' && mas[i][j - 1] != K && mas[i][j - 1] != '0' && find(a.begin(), a.end(), mas[i][j - 1]) == a.end()) { l++; a.push_back(mas[i][j + 1]); }
				if (mas[i][j + 1] != '.' && mas[i][j + 1] != K && mas[i][j + 1] != '0' && find(a.begin(), a.end(), mas[i][j + 1]) == a.end()) { l++; a.push_back(mas[i][j - 1]); }*/
				if (find(a.begin(), a.end(), mas[i - 1][j]) == a.end()) { l++; a.push_front(mas[i - 1][j]); }
				if (find(a.begin(), a.end(), mas[i + 1][j]) == a.end()) { l++; a.push_front(mas[i + 1][j]); }
				if (find(a.begin(), a.end(), mas[i][j - 1]) == a.end()) { l++; a.push_front(mas[i][j - 1]); }
				if (find(a.begin(), a.end(), mas[i][j + 1]) == a.end()) { l++; a.push_front(mas[i][j + 1]); }
			}
		}
	}
	cout << l;
	a.clear();
	for (int i = 0; i < n; i++)
		delete[] mas[i];
	delete[] mas;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n, m;
	char K;
	cin >> n >> m >> K;
	n += 2;
	m += 2;
	char** mas = new char*[n];
	for (int i = 0; i < n; i++)
		mas[i] = new char[m];
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			mas[i][j] = '0';
		}
	}
	for (int i = 1; i < n-1; i++){
		for (int j = 1; j < m-1; j++){
			cin >> mas[i][j];
		}
	}
	vector<char> a;
	int l = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (mas[i][j] == K){
				if (mas[i - 1][j] != '.' && mas[i - 1][j] != K && mas[i - 1][j] != '0' && find(a.begin(), a.end(), mas[i - 1][j]) == a.end()) { l++; a.push_back(mas[i - 1][j]); }
				if (mas[i + 1][j] != '.' && mas[i + 1][j] != K && mas[i + 1][j] != '0' && find(a.begin(), a.end(), mas[i + 1][j]) == a.end()) { l++; a.push_back(mas[i + 1][j]); }
				if (mas[i][j - 1] != '.' && mas[i][j - 1] != K && mas[i][j - 1] != '0' && find(a.begin(), a.end(), mas[i][j - 1]) == a.end()) { l++; a.push_back(mas[i][j + 1]); }
				if (mas[i][j + 1] != '.' && mas[i][j + 1] != K && mas[i][j + 1] != '0' && find(a.begin(), a.end(), mas[i][j + 1]) == a.end()) { l++; a.push_back(mas[i][j - 1]); }
			}
		}
	}
	cout << l;
	a.clear();
	for (int i = 0; i < n; i++)
		delete[] mas[i];
	delete[] mas;
	return 0;
}


#include <vector>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define INF 1e8
#define EPS 1e-8
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

char a[110][110];
int n,m;
int main()
{
	//freopen("a.in","r",stdin);
	register int i,j;
	while(cin>>n>>m)
	{
		char c;
		cin>>c;
		CLR(a,0);
		FR(i,n)FR(j,m) cin>>a[i][j];
		bool visited[27] = {false};
		visited[c-'A']=true;
		int sum = 0;
		FR(i,n) FR(j,n)
		{
			if(a[i][j] == c)
			{
				if(isupper(a[i-1][j]) && !visited[a[i-1][j]-'A'])
				{
					visited[a[i-1][j]-'A'] = true;
					sum++;
				}
				if(isupper(a[i+1][j]) && !visited[a[i+1][j]-'A'])
				{
					visited[a[i+1][j]-'A'] = true;
					sum++;
				}
				if(isupper(a[i][j-1]) && !visited[a[i][j-1]-'A'])
				{
					visited[a[i][j-1]-'A'] = true;
					sum++;
				}
				if(isupper(a[i][j+1]) && !visited[a[i][j+1]-'A'])
				{
					visited[a[i][j+1]-'A'] = true;
					sum++;
				}

			}
		}
		cout<<sum<<endl;
	}

}


#include <vector>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define INF 1e8
#define EPS 1e-8
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

char a[110][110];
int n,m;
int main()
{
	//freopen("a.in","r",stdin);
	register int i,j;
	while(cin>>n>>m)
	{
		char c;
		cin>>c;
		CLR(a,0);
		FR(i,n)FR(j,m) cin>>a[i][j];
		bool visited[27] = {false};
		visited[c-'A']=true;
		int sum = 0;
		FR(i,n) FR(j,m)
		{
			if(a[i][j] == c)
			{
				if(i>0 && isupper(a[i-1][j]) && !visited[a[i-1][j]-'A'])
				{
					visited[a[i-1][j]-'A'] = true;
					sum++;
				}
				if(isupper(a[i+1][j]) && !visited[a[i+1][j]-'A'])
				{
					visited[a[i+1][j]-'A'] = true;
					sum++;
				}
				if(j>0 && isupper(a[i][j-1]) && !visited[a[i][j-1]-'A'])
				{
					visited[a[i][j-1]-'A'] = true;
					sum++;
				}
				if(isupper(a[i][j+1]) && !visited[a[i][j+1]-'A'])
				{
					visited[a[i][j+1]-'A'] = true;
					sum++;
				}

			}
		}
		cout<<sum<<endl;
	}

}


#include <vector>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define INF 1e8
#define EPS 1e-8
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

char a[110][110];
int n,m;
int main()
{
	//freopen("a.in","r",stdin);
	register int i,j;
	while(cin>>n>>m)
	{
		char c;
		cin>>c;
		CLR(a,0);
		FR(i,n)FR(j,m) cin>>a[i][j];
		bool visited[27] = {false};
		int sum = 0;
		FR(i,n) FR(j,n)
		{
			if(a[i][j] == c)
			{
				if(isupper(a[i-1][j]) && !visited[a[i-1][j]-'A'])
				{
					visited[a[i-1][j]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i+1][j]) && !visited[a[i+1][j]-'A'])
				{
					visited[a[i+1][j]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i][j-1]) && !visited[a[i][j-1]-'A'])
				{
					visited[a[i][j-1]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i][j+1]) && !visited[a[i][j+1]-'A'])
				{
					visited[a[i][j+1]-'A'] = true;
					sum++;
				}

			}
		}
		cout<<sum<<endl;
	}

}


#include <vector>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define INF 1e8
#define EPS 1e-8
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

char a[110][110];
int n,m;
int main()
{
	//freopen("a.in","r",stdin);
	register int i,j;
	while(cin>>n>>m)
	{
		char c;
		cin>>c;
		CLR(a,0);
		FR(i,n)FR(j,m) cin>>a[i][j];
		bool visited[27] = {false};
		visited[c-'A']=true;
		int sum = 0;
		FR(i,n) FR(j,m)
		{
			if(a[i][j] == c)
			{
				if(isupper(a[i-1][j]) && !visited[a[i-1][j]-'A'])
				{
					visited[a[i-1][j]-'A'] = true;
					sum++;
				}
				if(isupper(a[i+1][j]) && !visited[a[i+1][j]-'A'])
				{
					visited[a[i+1][j]-'A'] = true;
					sum++;
				}
				if(isupper(a[i][j-1]) && !visited[a[i][j-1]-'A'])
				{
					visited[a[i][j-1]-'A'] = true;
					sum++;
				}
				if(isupper(a[i][j+1]) && !visited[a[i][j+1]-'A'])
				{
					visited[a[i][j+1]-'A'] = true;
					sum++;
				}

			}
		}
		cout<<sum<<endl;
	}

}


#include <vector>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define INF 1e8
#define EPS 1e-8
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

char a[110][110];
int n,m;
int main()
{
	//freopen("a.in","r",stdin);
	register int i,j;
	while(cin>>n>>m)
	{
		char c;
		cin>>c;
		CLR(a,0);
		FR(i,n)FR(j,m) cin>>a[i][j];
		bool visited[27] = {false};
		visited[c-'A']=true;
		int sum = 0;
		FR(i,n) FR(j,n)
		{
			if(a[i][j] == c)
			{
				if(isupper(a[i-1][j]) && !visited[a[i-1][j]-'A'])
				{
					visited[a[i-1][j]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i+1][j]) && !visited[a[i+1][j]-'A'])
				{
					visited[a[i+1][j]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i][j-1]) && !visited[a[i][j-1]-'A'])
				{
					visited[a[i][j-1]-'A'] = true;
					sum++;
				}
				else if(isupper(a[i][j+1]) && !visited[a[i][j+1]-'A'])
				{
					visited[a[i][j+1]-'A'] = true;
					sum++;
				}

			}
		}
		cout<<sum<<endl;
	}

}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	int n, m, counter = 0;
	int letters[27];
	char arr[101][101];
	vector <int> prX;
	vector <int> prY;
	char prDesk;

	memset(letters, 0, sizeof letters);
	cin >> n >> m;
	cin >> prDesk;
	for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++)
	{
		cin >> arr[i][j];
		if (arr[i][j] == prDesk)
		{
			prX.push_back(i);
			prY.push_back(j);
		}
	}
	for (int i = 0; i < prX.size(); i++)
	{
		if ((prX[i] - 1) >= 0)
		{
			if (arr[prX[i] - 1][prY[i]] != '.' && arr[prX[i] - 1][prY[i]] != prDesk)
			{
				if (letters[arr[prX[i] - 1][prY[i]] - 'A'] == 0)
				{
					letters[arr[prX[i] - 1][prY[i]] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prX[i] + 1) < n)
		{
			if (arr[prX[i] + 1][prY[i]] != '.' && arr[prX[i] + 1][prY[i]] != prDesk)
			{
				if (letters[arr[prX[i] + 1][prY[i]] - 'A'] == 0)
				{
					letters[arr[prX[i] + 1][prY[i]] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prY[i] - 1) >= 0)
		{
			if (arr[prX[i]][prY[i] - 1] != '.' && arr[prX[i]][prY[i] - 1] != prDesk)
			{
				if (letters[arr[prX[i]][prY[i] - 1] - 'A'] == 0)
				{
					letters[arr[prX[i]][prY[i] - 1] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prY[i] + 1) < m)
		{
			if (arr[prX[i]][prY[i] + 1] != '.' && arr[prX[i]][prY[i] + 1] != prDesk)
			{
				if (letters[arr[prX[i]][prY[i] + 1] - 'A'] == 0)
				{
					letters[arr[prX[i]][prY[i] + 1] - 'A'] == 1;
					counter++;
				}
			}
		}
	}
	cout << counter;
	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	int n, m, counter = 0;
	int letters[27];
	char arr[101][101];
	vector <int> prX;
	vector <int> prY;
	char prDesk;

	memset(letters, 0, sizeof letters);
	cin >> n >> m;
	cin >> prDesk;
	for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++)
	{
		cin >> arr[i][j];
		if (arr[i][j] == prDesk)
		{
			prX.push_back(i);
			prY.push_back(j);
		}
	}
	for (int i = 0; i < prX.size(); i++)
	{
		if ((prX[i] - 1) >= 0)
		{
			if (arr[prX[i] - 1][prY[i]] != '.' && arr[prX[i] - 1][prY[i]] != prDesk)
			{
				if (letters[arr[prX[i] - 1][prY[i]] - 'A'] == 0)
				{
					letters[arr[prX[i] - 1][prY[i]] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prX[i] + 1) < n)
		{
			if (arr[prX[i] + 1][prY[i]] != '.' && arr[prX[i] + 1][prY[i]] != prDesk)
			{
				if (letters[arr[prX[i] + 1][prY[i]] - 'A'] == 0)
				{
					letters[arr[prX[i] + 1][prY[i]] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prY[i] - 1) >= 0)
		{
			if (arr[prX[i]][prY[i] - 1] != '.' && arr[prX[i]][prY[i] - 1] != prDesk)
			{
				if (letters[arr[prX[i]][prY[i] - 1] - 'A'] == 0)
				{
					letters[arr[prX[i]][prY[i] - 1] - 'A'] = 1;
					counter++;
				}
			}
		}

		if ((prY[i] + 1) < m)
		{
			if (arr[prX[i]][prY[i] + 1] != '.' && arr[prX[i]][prY[i] + 1] != prDesk)
			{
				if (letters[arr[prX[i]][prY[i] + 1] - 'A'] == 0)
				{
					letters[arr[prX[i]][prY[i] + 1] - 'A'] = 1;
					counter++;
				}
			}
		}
	}
	cout << counter;
	return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    map <char,int> mp;
    int n,m,i,j,d=0,t,res=0;
    char c;
    char color[22222];
    char cab[222][222];
    cin >> n >> m >> c;
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            cin >> cab [i][j];
        }
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            if (cab[i][j]==c)
            {
                color[d]=cab[i-1][j];
                d++;
                color[d]=cab[i+1][j];
                d++;
                color[d]=cab[i][j-1];
                d++;
                color[d]=cab[i][j+1];
                d++;
            }
        }
    }
    for (i=0;i<d;i++)
    {
        t=mp[color[i]];
        if ((t==0) && (color[i]!=46) && (color[i]!=c) && (color[i]!=-52))
            res++;
        t++;
        mp[color[i]]=t;
    }
    cout << res;

    return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    map <char,int> mp;
    int n,m,i,j,d=0,t,res=0;
    char c;
    char color[22222];
    char cab[222][222];
    cin >> n >> m >> c;
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            cin >> cab [i][j];
        }
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            if (cab[i][j]==c)
            {
                color[d]=cab[i-1][j];
                d++;
                color[d]=cab[i+1][j];
                d++;
                color[d]=cab[i][j-1];
                d++;
                color[d]=cab[i][j+1];
                d++;
            }
        }
    }
    for (i=0;i<d;i++)
    {
        t=mp[color[i]];
        if ((t==0) && (color[i]!=46) && (color[i]!=c) && (color[i]!=-52))
            res++;
        t++;
        mp[color[i]]=t;
    }
    cout << res;
    return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    map <char,int> mp;
    int n,m,i,j,d=0,t,res=0;
    char c;
    char color[22222];
    char cab[222][222];
    cin >> n >> m >> c;
    for (i=0;i<n+2;i++)
    {
        j=0;
        cab[i][j]=0;
        j=m+1;
        cab[i][j]=0;
    }
    for (j=0;j<m+2;j++)
    {
        i=0;
        cab[i][j]=0;
        i=n+1;
        cab[i][j]=0;
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            cin >> cab [i][j];
        }
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            if (cab[i][j]==c)
            {
                color[d]=cab[i-1][j];
                d++;
                color[d]=cab[i+1][j];
                d++;
                color[d]=cab[i][j-1];
                d++;
                color[d]=cab[i][j+1];
                d++;
            }
        }
    }
    for (i=0;i<d;i++)
    {
        t=mp[color[i]];
        if ((t==0) && (color[i]!=46) && (color[i]!=c) && (color[i]!=0))
            res++;
        t++;
        mp[color[i]]=t;
    }
    cout << res;
    system ("pause");
    return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    map <char,int> mp;
    int n,m,i,j,d=0,t,res=0;
    char c;
    char color[22222];
    char cab[222][222];
    cin >> n >> m >> c;
    for (i=0;i<n+2;i++)
    {
        j=0;
        cab[i][j]=0;
        j=m+1;
        cab[i][j]=0;
    }
    for (j=0;j<m+2;j++)
    {
        i=0;
        cab[i][j]=0;
        i=n+1;
        cab[i][j]=0;
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            cin >> cab [i][j];
        }
    }
    for (i=1;i<n+1;i++)
    {
        for (j=1;j<m+1;j++)
        {
            if (cab[i][j]==c)
            {
                color[d]=cab[i-1][j];
                d++;
                color[d]=cab[i+1][j];
                d++;
                color[d]=cab[i][j-1];
                d++;
                color[d]=cab[i][j+1];
                d++;
            }
        }
    }
    for (i=0;i<d;i++)
    {
        t=mp[color[i]];
        if ((t==0) && (color[i]!=46) && (color[i]!=c) && (color[i]!=0))
            res++;
        t++;
        mp[color[i]]=t;
    }
    cout << res;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int m,n;
    char color;
    cin>>m>>n>>color;
    cin.ignore();
    string str;
    char dom[102][102];
    memset(dom,'.',sizeof(dom));
    bool t = 0;
    int x_begin,y_begin;
    for (int i=0;i<m;i++){
        getline(cin,str);
        for (int j=0;j<str.length();j++){
            dom[i+1][j+1] = str[j];
            if (str[j]==color)
                if (t==0){
                    x_begin = i+1;
                    y_begin = j+1;
                    t = 1;
                }
        }
    }
    int cnt_r = 0;
    int j = y_begin;
    while (dom[x_begin][j] == color){
        cnt_r++;
        j++;
    }
    int cnt_d = 0;
    int i = x_begin;
    while (dom[i][y_begin] == color){
        cnt_d++;
        i++;
    }
    int x_end = x_begin + cnt_d ;
    int y_end = y_begin + cnt_r ;
    int ch[26];
    memset(ch,0,26*sizeof(int));
    for (j=y_begin;j<y_end;j++)
        if (isalpha(dom[x_begin-1][j]))
            ch[(int)dom[x_begin-1][j]-65]++;
    for (j=y_begin;j<y_end;j++)
        if (isalpha(dom[x_end][j]))
            ch[(int)dom[x_end][j]-65]++;
    for (i=x_begin;i<x_end;i++)
        if (isalpha(dom[i][y_begin-1]))
            ch[(int)dom[i][y_begin-1]-65]++;
    for (i=x_begin;i<x_end;i++)
        if (isalpha(dom[i][y_end]))
            ch[(int)dom[i][y_end]-65]++;
    int cnt=0;
    for (i=0;i<26;i++)
        if (ch[i]!=0&&i!=(int)color-65)
            cnt++;
    cout<<cnt<<endl;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
int main()
{
    int m,n;
    char color;
    cin>>m>>n>>color;
    char dom[100][100];
    bool t = 0;
    int x_begin,y_begin;
    for (int i=0;i<m;i++)
        for (int j=0;j<n;j++){
            cin>>dom[i][j];
            if (dom[i][j]==color)
                if (t==0){
                    x_begin = i;
                    y_begin = j;
                    t = 1;
                }
        }
    int cnt_r = 0;
    int j = y_begin;
    while (dom[x_begin][j] == color){
        cnt_r++;
        j++;
    }
        int cnt_d = 0;
    int i = x_begin;
    while (dom[i][y_begin] == color){
        cnt_d++;
        i++;
    }

    int x_end = x_begin + cnt_r - 1;
    int y_end = y_begin + cnt_d - 1;

    int ch[26];
    memset(ch,0,26);
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_begin-1][j]!='.')
            ch[(int)dom[x_begin-1][j]-65]++;
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_end+1][j]!='.')
            ch[(int)dom[x_end+1][j]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_begin-1]!='.')
            ch[(int)dom[i][y_begin-1]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_end+1]!='.')
            ch[(int)dom[i][y_end+1]-65]++;
    int cnt=0;
    for (i=0;i<26;i++)
        if (ch[i]!=0)
            cnt++;
    cout<<cnt<<endl;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
int main()
{
    int m,n;
    char color;
    cin>>n>>m>>color;
    char dom[100][100];
    bool t = 0;
    int x_begin,y_begin;
    for (int i=0;i<m;i++)
        for (int j=0;j<n;j++){
            cin>>dom[i][j];
            if (dom[i][j]==color)
                if (t==0){
                    x_begin = i;
                    y_begin = j;
                    t = 1;
                }
        }
    int cnt_r = 0;
    int j = y_begin;
    while (dom[x_begin][j] == color){
        cnt_r++;
        j++;
    }
    int cnt_d = 0;
    int i = x_begin;
    while (dom[i][y_begin] == color){
        cnt_d++;
        i++;
    }
    int x_end = x_begin + cnt_r - 1;
    int y_end = y_end + cnt_d - 1;

    int ch[26];
    memset(ch,0,26);
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_begin-1][j]!='.')
            ch[(int)dom[x_begin-1][j]-65]++;
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_end+1][j]!='.')
            ch[(int)dom[x_end+1][j]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_begin-1]!='.')
            ch[(int)dom[i][y_begin-1]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_end+1]!='.')
            ch[(int)dom[i][y_end+1]-65]++;
    int cnt=0;
    for (i=0;i<26;i++)
        if (ch[i]!=0)
            cnt++;
    cout<<cnt<<endl;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int m,n;
    char color;
    cin>>m>>n>>color;
    cin.ignore();
    string str;
    char dom[102][102];
    bool t = 0;
    int x_begin,y_begin;
    for (int i=0;i<m;i++){
        getline(cin,str);
        for (int j=0;j<str.length();j++){
            dom[i+1][j+1] = str[j];
            if (str[j]==color)
                if (t==0){
                    x_begin = i+1;
                    y_begin = j+1;
                    t = 1;
                }
        }
    }
    int cnt_r = 0;
    int j = y_begin;
    while (dom[x_begin][j] == color){
        cnt_r++;
        j++;
    }
    int cnt_d = 0;
    int i = x_begin;
    while (dom[i][y_begin] == color){
        cnt_d++;
        i++;
    }
    int x_end = x_begin + cnt_d ;
    int y_end = y_begin + cnt_r ;
    int ch[26];
    memset(ch,0,26*sizeof(int));
    for (j=y_begin;j<y_end;j++)
        if (isalpha(dom[x_begin-1][j]))
            ch[(int)dom[x_begin-1][j]-65]++;
    for (j=y_begin;j<y_end;j++)
        if (isalpha(dom[x_end][j]))
            ch[(int)dom[x_end][j]-65]++;
    for (i=x_begin;i<x_end;i++)
        if (isalpha(dom[i][y_begin-1]))
            ch[(int)dom[i][y_begin-1]-65]++;
    for (i=x_begin;i<x_end;i++)
        if (isalpha(dom[i][y_end]))
            ch[(int)dom[i][y_end]-65]++;
    int cnt=0;
    for (i=0;i<26;i++)
        if (ch[i]!=0&&i!=(int)color-65)
            cnt++;
    cout<<cnt<<endl;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
int main()
{
    int m,n;
    char color;
    cin>>m>>n>>color;
    char dom[100][100];
    bool t = 0;
    int x_begin,y_begin;
    for (int i=0;i<m;i++)
        for (int j=0;j<n;j++){
            cin>>dom[i][j];
            if (dom[i][j]==color)
                if (t==0){
                    x_begin = i;
                    y_begin = j;
                    t = 1;
                }
        }
    int cnt_r = 1;
    int i = x_begin + 1;
    while (dom[i][y_begin] == color){
        cnt_r++;
        i++;
    }
    int cnt_d = 1;
    int j = y_begin + 1;
    while (dom[x_begin][j] == color){
        cnt_d++;
        j++;
    };
    int x_end = x_begin + cnt_r - 1;
    int y_end = y_end + cnt_d - 1;

    int ch[26];
    memset(ch,0,26);
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_begin-1][j]!='.')
            ch[(int)dom[x_begin-1][j]-65]++;
    for (j=y_begin;j<y_end+1;j++)
        if (dom[x_end+1][j]!='.')
            ch[(int)dom[x_end+1][j]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_begin-1]!='.')
            ch[(int)dom[i][y_begin-1]-65]++;
    for (i=x_begin;i<x_end+1;i++)
        if (dom[i][y_end+1]!='.')
            ch[(int)dom[i][y_end+1]-65]++;
    int cnt=0;
    for (i=0;i<26;i++)
        if (ch[i]!=0)
            cnt++;
    cout<<cnt<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

char c;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    set <char> d;
    vector <pair <int,int> > q;
    int n,m;
    scanf ("%d %d %c\n", &n, &m, &c);
    vector <vector <char> > a(n);
    forn(i,n)
        a[i].resize(m);
    forn(i,n){
        forn(j,m){
            scanf ("%c", &a[i][j]);
            if (a[i][j]==c) q.pb(mp(i,j));
        }
        scanf ("\n");
    }
    int ans=0;
    forn(i,q.size()){
        if (q[i].x!=n-1) {
            if (a[q[i].x+1][q[i].y]!='.' && a[q[i].x+1][q[i].y]!=c && d.find(a[q[i].x+1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x+1][q[i].y]);
            }
        }
        if (q[i].x!=0) {
            if (a[q[i].x-1][q[i].y]!='.' && a[q[i].x-1][q[i].y]!=c && d.find(a[q[i].x-1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x-1][q[i].y]);
            }
        }
        if (q[i].y!=n-1) {
            if (a[q[i].x][q[i].y+1]!='.' && a[q[i].x][q[i].y+1]!=c && d.find(a[q[i].x][q[i].y]+1)==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y+1]);
            }
        }
        if (q[i].x!=0) {
            if (a[q[i].x][q[i].y-1]!='.' && a[q[i].x][q[i].y-1]!=c && d.find(a[q[i].x][q[i].y-1])==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y-1]);
            }
        }
    }
    printf ("%d", ans);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

char c;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    set <char> d;
    vector <pair <int,int> > q;
    int n,m;
    scanf ("%d %d %c\n", &n, &m, &c);
    vector <vector <char> > a(n);
    forn(i,n)
        a[i].resize(m);
    forn(i,n){
        forn(j,m){
            scanf ("%c", &a[i][j]);
            if (a[i][j]==c) q.pb(mp(i,j));
        }
        scanf ("\n");
    }
    int ans=0;
    forn(i,q.size()){
        if (q[i].x!=n-1) {
            if (a[q[i].x+1][q[i].y]!='.' && a[q[i].x+1][q[i].y]!=c && d.find(a[q[i].x+1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x+1][q[i].y]);
            }
        }
        if (q[i].x!=0) {
            if (a[q[i].x-1][q[i].y]!='.' && a[q[i].x-1][q[i].y]!=c && d.find(a[q[i].x-1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x-1][q[i].y]);
            }
        }
        if (q[i].y!=m-1) {
            if (a[q[i].x][q[i].y+1]!='.' && a[q[i].x][q[i].y+1]!=c && d.find(a[q[i].x][q[i].y]+1)==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y+1]);
            }
        }
        if (q[i].y!=0) {
            if (a[q[i].x][q[i].y-1]!='.' && a[q[i].x][q[i].y-1]!=c && d.find(a[q[i].x][q[i].y-1])==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y-1]);
            }
        }
    }
    printf ("%d", ans);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

char c;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    set <char> d;
    vector <pair <int,int> > q;
    int n,m;
    scanf ("%d %d %c\n", &n, &m, &c);
    vector <vector <char> > a(n);
    forn(i,n)
        a[i].resize(m);
    forn(i,n){
        forn(j,m){
            scanf ("%c", &a[i][j]);
            if (a[i][j]==c) q.pb(mp(i,j));
        }
        scanf ("\n");
    }
    int ans=0;
    forn(i,q.size()){
        if (q[i].x!=n-1) {
            if (a[q[i].x+1][q[i].y]!='.' && a[q[i].x+1][q[i].y]!=c && d.find(a[q[i].x+1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x+1][q[i].y]);
            }
        }
        if (q[i].x!=0) {
            if (a[q[i].x-1][q[i].y]!='.' && a[q[i].x-1][q[i].y]!=c && d.find(a[q[i].x-1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x-1][q[i].y]);
            }
        }
        if (q[i].y!=n-1) {
            if (a[q[i].x][q[i].y+1]!='.' && a[q[i].x][q[i].y+1]!=c && d.find(a[q[i].x][q[i].y]+1)==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y+1]);
            }
        }
        if (q[i].y!=0) {
            if (a[q[i].x][q[i].y-1]!='.' && a[q[i].x][q[i].y-1]!=c && d.find(a[q[i].x][q[i].y-1])==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y-1]);
            }
        }
    }
    printf ("%d", ans);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

char c;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    set <char> d;
    vector <pair <int,int> > q;
    int n,m;
    scanf ("%d %d %c\n", &n, &m, &c);
    vector <vector <char> > a(n);
    forn(i,n)
        a[i].resize(m);
    forn(i,n){
        forn(j,m){
            scanf ("%c", &a[i][j]);
            if (a[i][j]==c) q.pb(mp(i,j));
        }
        scanf ("\n");
    }
    int ans=0;
    forn(i,q.size()){
        if (q[i].x!=n-1) {
            if (a[q[i].x+1][q[i].y]!='.' && a[q[i].x+1][q[i].y]!=c && d.find(a[q[i].x+1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x+1][q[i].y]);
            }
        }
        if (q[i].x!=0) {
            if (a[q[i].x-1][q[i].y]!='.' && a[q[i].x-1][q[i].y]!=c && d.find(a[q[i].x-1][q[i].y])==d.end()){
                ans++;
                d.insert(a[q[i].x-1][q[i].y]);
            }
        }
        if (q[i].y!=m-1) {
            if (a[q[i].x][q[i].y+1]!='.' && a[q[i].x][q[i].y+1]!=c && d.find(a[q[i].x][q[i].y+1])==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y+1]);
            }
        }
        if (q[i].y!=0) {
            if (a[q[i].x][q[i].y-1]!='.' && a[q[i].x][q[i].y-1]!=c && d.find(a[q[i].x][q[i].y-1])==d.end()){
                ans++;
                d.insert(a[q[i].x][q[i].y-1]);
            }
        }
    }
    printf ("%d", ans);
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,m;
    char Pres_color;
    string desks;
    cin>>n>>m>>Pres_color;
    int c = 0;
    char **office = new char*[n];
    for(int i=0 ; i< n;i++)
    {
        office[i] = new char[m];
        for(int j=0;j<m;j++)
        {
            cin>>office[i][j];
            if(office[i][j]==Pres_color)
                c++;
        }
    }
    if(c==0)
    {
        cout<<'0'<<endl;
        return 0;
    }
    while(c>0)
    {
        for(int i=0 ; i< n;i++)
            for(int j=0;j<m;j++)
            {
                if(office[i][j]==Pres_color)
                {
                    if(i!=0)
                    {
                        char up = office[i-1][j];
                        if(desks.find(up)==-1 && up != '.' && up != Pres_color )
                        desks+=up;
                    }
                    if(i+1!=n)
                    {
                        char down = office[i+1][j];
                        if(desks.find(down)==-1 && down != '.' && down != Pres_color )
                        desks+=down;
                    }
                    if(j+1!=m)
                    {
                        char right = office[i][j+1];
                        if(desks.find(right)==-1 && right != '.' && right != Pres_color )
                        desks+=right;
                    }
                    if(j!=0)
                    {
                        char left = office[i][j-1];
                        if(desks.find(left)==-1 && left != '.' && left != Pres_color )
                        desks+=left;
                    }
                }
            }
        c--;
    }
    cout<<desks.length()<<endl;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int c = 0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
				c++;
		}
	}
	if(c==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	while(c>0)
	{
		for(int i=0 ; i< n;i++)
			for(int j=0;j<m;j++)
			{
				if(office[i][j]==Pres_color)
				{
					if(i!=0)
					{
						char up = office[i-1][j];
						if(desks.find(up)==-1 && up != '.' && up != Pres_color )
						desks+=up;
					}
					if(i+1!=n)
					{
						char down = office[i+1][j];
						if(desks.find(down)==-1 && down != '.' && down != Pres_color )
						desks+=down;
					}
					if(j+1!=m)
					{
						char right = office[i][j+1];
						if(desks.find(right)==-1 && right != '.' && right != Pres_color )
						desks+=right;
					}
					if(j!=0)
					{
						char left = office[i][j-1];
						if(desks.find(left)==-1 && left != '.' && left != Pres_color )
						desks+=left;
					}
				}
			}
		c--;
	}
	cout<<desks.length()<<endl;
//
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int **c = new int *[1000];
	int k=0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
			{
				c[k] = new int[2];
				c[k][0] = i; c[k][1] = j;
				k++;
			}
		}
	}
	if(k==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	for(int i=0 ; i<k ; i++)
	{
		if((c[i][0])!=0)
		{
			char up = office[(c[i][0])-1][(c[i][1])];
			if(desks.find(up)==-1 && up != '.' && up != Pres_color )
			desks+=up;
		}
		if((c[i][0])+1!=n)
		{
			char down = office[(c[i][0])+1][(c[i][1])];
			if(desks.find(down)==-1 && down != '.' && down != Pres_color )
			desks+=down;
		}
		if((c[i][1])+1!=m)
		{
			char right = office[(c[i][0])][(c[i][1])+1];
			if(desks.find(right)==-1 && right != '.' && right != Pres_color )
			desks+=right;
		}
		if((c[i][1])!=0)
		{
			char left = office[(c[i][0])][(c[i][1])-1];
			if(desks.find(left)==-1 && left != '.' && left != Pres_color )
			desks+=left;
		}
	}
	cout<<desks.length()<<endl;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int **c = new int *[100];
	int k=0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
			{
				c[k] = new int[2];
				c[k][0] = i; c[k][1] = j;
				k++;
			}
		}
	}
	if(k==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	for(int i=0 ; i<k ; i++)
	{
		if((c[i][0])!=0)
		{
			char up = office[(c[i][0])-1][(c[i][1])];
			if(desks.find(up)==-1 && up != '.' && up != Pres_color )
			desks+=up;
		}
		if((c[i][0])+1!=n)
		{
			char down = office[(c[i][0])+1][(c[i][1])];
			if(desks.find(down)==-1 && down != '.' && down != Pres_color )
			desks+=down;
		}
		if((c[i][1])+1!=m)
		{
			char right = office[(c[i][0])][(c[i][1])+1];
			if(desks.find(right)==-1 && right != '.' && right != Pres_color )
			desks+=right;
		}
		if((c[i][1])!=0)
		{
			char left = office[(c[i][0])][(c[i][1])-1];
			if(desks.find(left)==-1 && left != '.' && left != Pres_color )
			desks+=left;
		}
	}
	cout<<desks.length()<<endl;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int **c = new int *[10000];
	int k=0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
			{
				c[k] = new int[2];
				c[k][0] = i; c[k][1] = j;
				k++;
			}
		}
	}
	if(k==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	for(int i=0 ; i<k ; i++)
	{
		if((c[i][0])!=0)
		{
			char up = office[(c[i][0])-1][(c[i][1])];
			if(desks.find(up)==-1 && up != '.' && up != Pres_color )
			desks+=up;
		}
		if((c[i][0])+1!=n)
		{
			char down = office[(c[i][0])+1][(c[i][1])];
			if(desks.find(down)==-1 && down != '.' && down != Pres_color )
			desks+=down;
		}
		if((c[i][1])+1!=m)
		{
			char right = office[(c[i][0])][(c[i][1])+1];
			if(desks.find(right)==-1 && right != '.' && right != Pres_color )
			desks+=right;
		}
		if((c[i][1])!=0)
		{
			char left = office[(c[i][0])][(c[i][1])-1];
			if(desks.find(left)==-1 && left != '.' && left != Pres_color )
			desks+=left;
		}
	}
	cout<<desks.length()<<endl;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int c = 0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
				c++;
		}
	}
	if(c==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	while(c>0)
	{
		for(int i=0 ; i< n;i++)
			for(int j=0;j<m;j++)
			{
				if(office[i][j]==Pres_color)
				{
					if(i!=0)
					{
						char up = office[i-1][j];
						if(desks.find(up)==-1 && up != '.' && up != Pres_color )
						desks+=up;
					}
					if(i+1!=n)
					{
						char down = office[i+1][j];
						if(desks.find(down)==-1 && down != '.' && down != Pres_color )
						desks+=down;
					}
					if(j+1!=m)
					{
						char right = office[i][j+1];
						if(desks.find(right)==-1 && right != '.' && right != Pres_color )
						desks+=right;
					}
					if(j!=0)
					{
						char left = office[i][j-1];
						if(desks.find(left)==-1 && left != '.' && left != Pres_color )
						desks+=left;
					}
				}
			}
		c--;
	}
	cout<<desks.length()<<endl;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,m;
	char Pres_color;
	string desks;
	cin>>n>>m>>Pres_color;
	int **c = new int *[500];
	int k=0;
	char **office = new char*[n];
	for(int i=0 ; i< n;i++)
	{
		office[i] = new char[m];
		for(int j=0;j<m;j++)
		{
			cin>>office[i][j];
			if(office[i][j]==Pres_color)
			{
				c[k] = new int[2];
				c[k][0] = i; c[k][1] = j;
				k++;
			}
		}
	}
	if(k==0)
	{
		cout<<'0'<<endl;
		return 0;
	}
	for(int i=0 ; i<k ; i++)
	{
		if((c[i][0])!=0)
		{
			char up = office[(c[i][0])-1][(c[i][1])];
			if(desks.find(up)==-1 && up != '.' && up != Pres_color )
			desks+=up;
		}
		if((c[i][0])+1!=n)
		{
			char down = office[(c[i][0])+1][(c[i][1])];
			if(desks.find(down)==-1 && down != '.' && down != Pres_color )
			desks+=down;
		}
		if((c[i][1])+1!=m)
		{
			char right = office[(c[i][0])][(c[i][1])+1];
			if(desks.find(right)==-1 && right != '.' && right != Pres_color )
			desks+=right;
		}
		if((c[i][1])!=0)
		{
			char left = office[(c[i][0])][(c[i][1])-1];
			if(desks.find(left)==-1 && left != '.' && left != Pres_color )
			desks+=left;
		}
	}
	cout<<desks.length()<<endl;
}


#include <stdio.h>
#include <string.h>

#define Max(a,b) ((a)>(b)?(a):(b))

__int64 C(int n,int m)
{
    int i;
    __int64 mm=1,nn=1;
    for(i=mm=1;i<=m;i++)
        mm*=i;
    for(i=0,nn=1;i<m;i++)
        nn *= (n-i);
    return nn/mm;
}

int main()
{
    int n,m,k;
    while(scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
        if(m<=k)
            printf("1\n");
        else
            printf("%.6lf\n",double(C(n+m,m)-C(n+m,m-k-1))*1.0/C(n+m,m)*1.0);
    }
    return 0;
}


#include <iostream>
#define MAXN 110
using namespace std;

int n,m;

bool flag[26];
char map[MAXN][MAXN],ch;

int main()
{
    int i,j,cnt;
    while(scanf(" %d%d%c",&n,&m,&ch)!=EOF)
    {
        memset(map,ch,sizeof(map));
        memset(flag,false,sizeof(flag));
        flag[ch-'a'] = true;
        cnt = 0;
        for(i=1;i<=n;i++)
            scanf(" %s",&map[1]);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(map[i][j]==ch)
                {
                    if(map[i-1][j]!='.'&&!flag[map[i-1][j]-'a'])
                    {
                        flag[map[i-1][j]-'a'] = true;
                        cnt++;
                    }
                    if(map[i+1][j]!='.'&&!flag[map[i+1][j]-'a'])
                    {
                        flag[map[i+1][j]-'a'] = true;
                        cnt++;
                    }
                    if(map[i][j+1]!='.'&&!flag[map[i][j+1]-'a'])
                    {
                        flag[map[i][j+1]-'a'] = true;
                        cnt++;
                    }
                    if(map[i][j-1]!='.'&&!flag[map[i][j-1]-'a'])
                    {
                        flag[map[i][j-1]-'a'] = true;
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <iostream>
#define MAXN 110
using namespace std;

int n,m;

bool flag[26];
char map[MAXN][MAXN],ch;

int main()
{
    int i,j,cnt;
    while(scanf(" %d%d%c",&n,&m,&ch)!=EOF)
    {
        gets(map[0]);
        memset(map,ch,sizeof(map));
        memset(flag,false,sizeof(flag));
        flag[ch-'A'] = true;
        cnt = 0;
        for(i=1;i<=n;i++)
            scanf(" %s",&map[i][1]);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(map[i][j]==ch)
                {
                    if(map[i-1][j]!='.'&&!flag[map[i-1][j]-'A'])
                    {
                        flag[map[i-1][j]-'A'] = true;
                        cnt++;
                    }
                    if(map[i+1][j]!='.'&&!flag[map[i+1][j]-'A'])
                    {
                        flag[map[i+1][j]-'A'] = true;
                        cnt++;
                    }
                    if(map[i][j+1]!='.'&&!flag[map[i][j+1]-'A'])
                    {
                        flag[map[i][j+1]-'A'] = true;
                        cnt++;
                    }
                    if(map[i][j-1]!='.'&&!flag[map[i][j-1]-'A'])
                    {
                        flag[map[i][j-1]-'A'] = true;
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;

#define MAXN 110

char map[MAXN][MAXN];
bool flag[30];

int main() {
	int n, m, i, j;
	char desk_ch;
	int result;
	while(scanf(" %d %d %c", &n, &m, &desk_ch) != EOF) {
		memset(map, '.', sizeof(map));
		memset(flag, false, sizeof(flag));
		for(i = 1; i <= n; i++) {
			for(j = 1; j <= m; j++) {
				scanf(" %c", &map[i][j]);
			}
		}
		for(i = 1; i <= n; i++) {
			for(j = 1; j <= m; j++) {
				if(map[i][j] != '.' && map[i][j] != desk_ch) {
					if(map[i - 1][j] == desk_ch || map[i + 1][j] == desk_ch || map[i][j - 1] == desk_ch || map[i][j + 1] == desk_ch)
						flag[map[i][j] - 'A'] = true;
				}
			}
		}
		for(i = result = 0; i < 26; i++) {
			if(flag[i])
				result++;
		}
		cout << result << endl;
	}
	return 0;
}


#include <iostream>
#define MAXN 110
using namespace std;

int n,m;

bool flag[26];
char map[MAXN][MAXN],ch;

int main()
{
    int i,j,cnt;
    while(scanf(" %d%d%c",&n,&m,&ch)!=EOF)
    {
        memset(map,ch,sizeof(map));
        memset(flag,false,sizeof(flag));
        flag[ch-'a'] = true;
        cnt = 0;
        for(i=1;i<=n;i++)
            scanf(" %s",&map[1]);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(map[i][j]==ch)
                {
                    if(map[i-1][j]!='.'&&!flag[map[i-1][j]])
                    {
                        flag[map[i-1][j]] = true;
                        cnt++;
                    }
                    if(map[i+1][j]!='.'&&!flag[map[i+1][j]])
                    {
                        flag[map[i+1][j]] = true;
                        cnt++;
                    }
                    if(map[i][j+1]!='.'&&!flag[map[i][j+1]])
                    {
                        flag[map[i][j+1]] = true;
                        cnt++;
                    }
                    if(map[i][j-1]!='.'&&!flag[map[i][j-1]])
                    {
                        flag[map[i][j-1]] = true;
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <iostream>
#define MAXN 110
using namespace std;

int n,m;

bool flag[26];
char map[MAXN][MAXN],ch;

int main()
{
    int i,j,cnt;
    while(scanf(" %d%d%c",&n,&m,&ch)!=EOF)
    {
        gets(map[0]);
        memset(map,ch,sizeof(map));
        memset(flag,false,sizeof(flag));
        flag[ch-'A'] = true;
        cnt = 0;
        for(i=1;i<=n;i++)
            scanf(" %s",&map[i]);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(map[i][j]==ch)
                {
                    if(map[i-1][j]!='.'&&!flag[map[i-1][j]-'A'])
                    {
                        flag[map[i-1][j]-'A'] = true;
                        cnt++;
                    }
                    if(map[i+1][j]!='.'&&!flag[map[i+1][j]-'A'])
                    {
                        flag[map[i+1][j]-'A'] = true;
                        cnt++;
                    }
                    if(map[i][j+1]!='.'&&!flag[map[i][j+1]-'A'])
                    {
                        flag[map[i][j+1]-'A'] = true;
                        cnt++;
                    }
                    if(map[i][j-1]!='.'&&!flag[map[i][j-1]-'A'])
                    {
                        flag[map[i][j-1]-'A'] = true;
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

#define ll long long

//ll int array[2*10^5];

int main() {

    int n,s;
    cin >> n >> s;

    int array[200000-1];
    for(int i = 0 ;i < n ;++i){
        cin >> array[i];
    }

    sort(array,array+n);

    int mid  = (int)((n-1)/2);

    if (array[mid] >s ){
        int count = 0;
        int index = 0;
        for(int i = 0 ; i < n ;++i){
            if (array[i] >= s){
                index = i;
                break;
            }
        }

        for (int i = index ; i <= mid ;++i){
            count += array[i]-s;
        }
        cout << count << endl;

    }
    else{
        int count = 0;
        int index = 0;
        for(int i = n-1 ; i !=0 ;--i){
            if (array[i] <= s){
                index = i;
                break;
            }
        }
        for (int i = mid ; i <= index ;++i){
            count += s- array[i];
        }

        cout << count << endl;

    }

    return 0;
}


#define _USE_MATH_DEFINES
#include <assert.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long     ll;
typedef unsigned int  UInt;
#define ALL(a)          (a).begin(), (a).end()
#define FOR(i,a,b)      for(int i = a;   i <  (int)(b); ++i)
#define FOR_REV(i,a,b)  for(int i = b-1; i >= (int)(a); --i)
#define FOR_EACH(it,a)  for(remove_reference<decltype(a)>::type::iterator it = (a).begin(); it != (a).end(); ++it)
#define FOR_EACH_REV(it,a) for(remove_reference<decltype(a)>::type::reverse_iterator it = (a).rbegin(); it != (a).rend(); ++it)
#define FOR_EACH_CONST(it,a) for(remove_reference<decltype(a)>::type::const_iterator it = (a).begin(); it != (a).end(); ++it)
#define FOR_EACH_CONST_REV(it,a) for(remove_reference<decltype(a)>::type::const_reverse_iterator it = (a).rbegin(); it != (a).rend(); ++it)
template<class T> inline T   sqr(T v)  { return v * v; }
template<class T> inline int sign(T v) { return v == 0 ? 0 : (v > 0 ? 1 : -1); }
template<class T> inline int get_bit(T v, int bit_index) { return (v >> bit_index) & 1; } //return {0,1}
template<class T> inline T   gcd(T a, T b) { while(b) { T t = b; b   = a % b; a   = t; } return a; }
#define IN_INT(a)            int a;       is >> a;
#define IN_INT2(a,b)         int a,b;     is >> a >> b;
#define IN_INT3(a,b,c)       int a,b,c;   is >> a >> b >> c;
#define IN_INT4(a,b,c,d)     int a,b,c,d; is >> a >> b >> c >> d;
#define IN_LL(a)             ll a;        is >> a;
#define IN_LL2(a,b)          ll a,b;      is >> a >> b;
#define IN_LL3(a,b,c)        ll a,b,c;    is >> a >> b >> c;
#define IN_LL4(a,b,c,d)      ll a,b,c,d;  is >> a >> b >> c >> d;
#define IN_STR(s)            string s;    is >> s;

//////////////////////////////////////////////////////////////////////////

istream& input(bool release_tie = false)
{
  ios_base::sync_with_stdio(false);
#ifdef INPUT_FROM_FILE
  static ifstream is("CodeForces/input.txt");
  return is;
#endif
  if (release_tie)
    cin.tie(NULL);
  return cin;
}

ostream& output(bool release_tie = false)
{
  cout << setprecision(15);
  if (release_tie)
    cout.tie(NULL);
  return cout;
}

template <typename T>
void init_v2(vector<vector<T>>& v, int lx, int ly, const T& val = T())
{
  v.resize(lx);
  FOR (i,0,lx)
    v[i].resize(ly, val);
};

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//a
//void main()
//{
//  istream& is = input();
//  ostream& os = output();
//
//  IN_INT(n);
//  int s = 0,res=0;
//
//  while (s<n)
//  {
//    s+=s+1;
//    ++res;
//  }
//  os << res;
//}

//////////////////////////////////////////////////////////////////////////
//b
void main()
{
  istream& is = input();
  ostream& os = output();

  IN_INT2(n,s);

  vector<int> a(n);
  FOR (i,0,n)
    is >> a[i];
  sort(ALL(a));

  ll res = 0;

  FOR (i,0,n/2)
    res+=max(0,a[i]-s);
  res+=abs(a[n/2]-s);
  FOR (i,n/2+1,n)
    res+=max(0,s-a[i]);

  os << res;
}

//////////////////////////////////////////////////////////////////////////

//void main()
//{
//  istream& is = input();
//  ostream& os = output();
//
//  IN_INT(n);
//
//  //vector<int> a(n);
//  //FOR (i,0,n)
//  //  is >> a[i];
//
//  //int res = 0;
//  //os << res;
//}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

static int n;
static int s;
static int A[200000];

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    int m = n / 2;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    sort(A, A+n);
    long long ans = 0;
    if (A[m] < s) {
        for (int i = m; i < n && A[i] < s; i++)
            ans += s - A[i];
    } else if (A[m] > s) {
        for (int i = m; i >= 0 && A[i] > s; i--)
            ans += A[i] - s;
    }
    cout << ans << '\n';
    return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

static int n;
static int s;
static int A[200000];

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    int m = n / 2;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    sort(A, A+n);
    long long ans = 0;
    if (A[m] < s) {
        for (int i = m; i < n && A[i] < s; i++)
            ans += s - A[i];
    } else if (A[m] > s) {
        for (int i = m; i >= 0 && A[i] > s; i++)
            ans += A[i] - s;
    }
    cout << ans << '\n';
    return 0;
}


#define DEBUG 0

#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
#define LD long double
#define PR pair<int,int>

#define Fox(i,n) for (i=0; i<n; i++)
#define Fox1(i,n) for (i=1; i<=n; i++)
#define FoxI(i,a,b) for (i=a; i<=b; i++)
#define FoxR(i,n) for (i=(n)-1; i>=0; i--)
#define FoxR1(i,n) for (i=n; i>0; i--)
#define FoxRI(i,a,b) for (i=b; i>=a; i--)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define Sz(s) int((s).size())
#define All(s) (s).begin(),(s).end()
#define Fill(s,v) memset(s,v,sizeof(s))
#define pb push_back
#define mp make_pair
#define x first
#define y second

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }
template<typename T> T Sqr(T x) { return(x*x); }
string plural(string s) { return(Sz(s) && s[Sz(s)-1]=='x' ? s+"en" : s+"s"); }

const int INF = (int)1e9;
const LD EPS = 1e-12;
const LD PI = acos(-1.0);

//#if DEBUG
#define GETCHAR getchar
/*#else
#define GETCHAR getchar_unlocked
#endif*/

bool Read(int &x)
{
	char c,r=0,n=0;
	x=0;
		for(;;)
		{
			c=GETCHAR();
				if ((c<0) && (!r))
					return(0);
				if ((c=='-') && (!r))
					n=1;
				else
				if ((c>='0') && (c<='9'))
					x=x*10+c-'0',r=1;
				else
				if (r)
					break;
		}
		if (n)
			x=-x;
	return(1);
}

#define MOD 1000000007
#define LIM 200005

int V[LIM];

int main()
{
		if (DEBUG)
			freopen("in.txt","r",stdin);
	int N,M,K;
	int i,j,k,a,b,c,x,y,z;
	Read(N),Read(K);
		Fox(i,N)
			Read(V[i]);
	sort(V,V+N);
	LL ans=0;
	j=N/2;
		Fox(i,N)
			if (i<j)
				ans+=max(0,V[i]-K);
			else
			if (i>j)
				ans+=max(0,K-V[i]);
			else
				ans+=Abs(K-V[i]);
	cout << ans << endl;
	return(0);
}


#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn=2e5+2;
int a[maxn];
int main()
{
    int n,s,i,sum;
    scanf("%d%d",&n,&s);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    sum=0;
    for(i=n/2;i<n;i++)
    {
        if(a[i]>=s)break;
        if(a[i]<s)sum=sum+(s-a[i]);
    }
    printf("%d\n",sum);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn=2e5+2;
long long a[maxn];
int main()
{
    int n,s,i;
    long long sum;
    scanf("%d%d",&n,&s);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    sum=0;
    for(i=n/2;i<n;i++)
    {
        if(a[i]>=s)break;
        if(a[i]<s)sum=sum+(s-a[i]);
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn=2e5+2;
int a[maxn];
int main()
{
    int n,s,i;
    long long sum;
    scanf("%d%d",&n,&s);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    sum=0;
    for(i=n/2;i<n;i++)
    {
        if(a[i]>=s)break;
        if(a[i]<s)sum=sum+(s-a[i]);
    }
    printf("%I64d\n",sum);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn=2e5+2;
long long a[maxn];
int main()
{
    int n,s,i,t;
    long long sum;
    scanf("%d%d",&n,&s);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    sum=0;
    t=n/2;
    if(a[t]!=s)
    {
        if(a[t]<s)
        {
            while(t<n)
            {
                sum+=s-a[t];
                t++;
                if(a[t]>=s)break;
            }
        }
        else if(a[t]>s)
        {
            while(t>=0)
            {
                sum+=a[t]-s;
                t--;
                if(a[t]<=s)break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int a[200010];

int main(int argc, char const *argv[])
{
	int n,k,x;
	ll ans;
	cin>>n>>k;
	for (int i=0; i<n; i++) cin>>a[i];

	sort(a, a+n);

	if (n==1) ans=a[0]-k;
	else {
		x=(n+1)/2;
		x--;
		ans=0;
		if (a[x]<k)
		{
			for (int i = x; i < n; i++)
			{
				if (a[i]<k)
				{
					ans+=k-a[i];
				}
				else break;
			}
		}
		else if (a[x]>k){
			for (int i = x; i >= 0; i--)
			{
				if (a[i]>k)
				{
					ans+=a[i]-k;
				}
				else break;
			}
		}
	}
	if (ans<0) ans*=(-1);

	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int a[200010];

int main(int argc, char const *argv[])
{
	int n,k,x,ans;
	cin>>n>>k;
	for (int i=0; i<n; i++) cin>>a[i];

	sort(a, a+n);

	if (n==1) ans=a[0]-k;
	else {
		x=(n+1)/2;
		x--;
		ans=0;
		if (a[x]<k)
		{
			for (int i = x; i < n; i++)
			{
				if (a[i]<k)
				{
					ans+=k-a[i];
				}
				else break;
			}
		}
		else if (a[x]>k){
			for (int i = x; i >= 0; i--)
			{
				if (a[i]>k)
				{
					ans+=a[i]-k;
				}
				else break;
			}
		}
	}
	if (ans<0) ans*=(-1);

	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int a[100010];

int main(int argc, char const *argv[])
{
	int n,k,x,ans;
	cin>>n>>k;
	for (int i=0; i<n; i++) cin>>a[i];

	sort(a, a+n);

	if (n==1) ans=a[0]-k;
	else {
		x=(n+1)/2;
		x--;
		ans=0;
		if (a[x]<k)
		{
			for (int i = x; i < n; i++)
			{
				if (a[i]<k)
				{
					ans+=k-a[i];
				}
				else break;
			}
		}
		else if (a[x]>k){
			for (int i = x; i >= 0; i--)
			{
				if (a[i]>k)
				{
					ans+=a[i]-k;
				}
				else break;
			}
		}
	}
	if (ans<0) ans*=(-1);

	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include<algorithm>
using namespace std;
long long a[200000];
int main()
{
    long long ans = 0, n, m, i, k;
    cin >> n >> m;
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a + n);
    k = n / 2;
    if(a[k] >= m)
    {
        for(i = k; i >= 0; i--)
        {
            if(a[i] <= m)
                break;
            ans += a[i] - m;
        }
    }
    else if(a[k] < m)
    {
        for(i = k; i < n; i++)
        {
            if(a[i] >= m)
            {
                break;
            }
            ans += m - a[i];
        }
    }
    cout << ans <<endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include<algorithm>
using namespace std;
long long a[200000];
int main()
{
    long long ans = 0, n, m, i, k;
    cin >> n >> m;
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a + n);
    k = n / 2;
    for(i = k; i < n; i++)
    {
        ans += m - a[i];
        if(a[i] >= m)
            break;
    }
    cout << ans <<endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
    int ans = 0, n, m, i, k;
    cin >> n >> m;
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a + n);
    k = n / 2;
    for(i = k; i < n; i++)
    {
        ans += m - a[i];
        if(a[i] >= m)
            break;
    }
    cout << ans <<endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define     lf(i,a,n)       for (int i=a;i<n;i++)
#define     ld(i,a,n)       for (int i=n-1;i>=a;i--)
#define     all(x)           (x).begin(),(x).end()
#define     SZ(x)            ((int)(x).size())
#define     CLR(a)           memset(a,0,sizeof(a))
#define     SET(a)           memset(a,-1,sizeof(a))

#define     li               long long int
#define     pii              pair<int,int>
#define     pli              pair<ll,ll>
#define     N                120
#define     M                1000000007
#define     fi               first
#define     se               second
#define     pb               push_back
#define     mp               make_pair

using namespace std;

template <class T> inline T gcd(T a, T b) { while (b) { a = a % b;swap(a, b); }return a; }
inline int ri() { int aaa;scanf("%d", &aaa);return aaa; }
inline li rl() { li aaa;scanf("%lld", &aaa);return aaa; }
inline double dxt() { double aaa;scanf("%lf", &aaa);return aaa; }

int main()
{
	int n = ri(), s = ri();

    vector<int> first;

	for (int i = 0; i < n; i++)
	{
		first.push_back(ri());

	}

	sort(all(first));

	int middle = n / 2;
	int op = 0;

	if (s != first[middle])
	{
		op += abs(s - first[middle]);
	}

	middle--;

	while (true)
	{
		if (middle < 0)
			break;

		if(first[n-middle-1]< s)
            op += abs(s - first[n - middle - 1]);

		if (first[middle] > s)
			op += abs(s - first[middle]);

		middle--;
	}
	cout << op << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define     lf(i,a,n)       for (int i=a;i<n;i++)
#define     ld(i,a,n)       for (int i=n-1;i>=a;i--)
#define     all(x)           (x).begin(),(x).end()
#define     SZ(x)            ((int)(x).size())
#define     CLR(a)           memset(a,0,sizeof(a))
#define     SET(a)           memset(a,-1,sizeof(a))

#define     li               long long int
#define     pii              pair<int,int>
#define     pli              pair<ll,ll>
#define     N                120
#define     M                1000000007
#define     fi               first
#define     se               second
#define     pb               push_back
#define     mp               make_pair

using namespace std;

template <class T> inline T gcd(T a, T b) { while (b) { a = a % b;swap(a, b); }return a; }
inline int ri() { int aaa;scanf("%d", &aaa);return aaa; }
inline li rl() { li aaa;scanf("%lld", &aaa);return aaa; }
inline double dxt() { double aaa;scanf("%lf", &aaa);return aaa; }

int main()
{
	int n = ri(), s = ri();

    vector<int> first;

	for (int i = 0; i < n; i++)
	{
		first.push_back(ri());

	}

	sort(all(first));

	int middle = n / 2;
	li op = 0;

	if (s != first[middle])
	{
		op += abs(s - first[middle]);
	}

	middle--;

	while (true)
	{
		if (middle < 0)
			break;

		if(first[n-middle-1]< s)
            op += abs(s - first[n - middle - 1]);

		if (first[middle] > s)
			op += abs(s - first[middle]);

		middle--;
	}
	cout << op << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <list>
#include <sstream>
#include <vector>
#include <clocale>
#include <stdlib.h>
#include <queue>
#include <fstream>

using namespace std;

//#define TRC(a)
#define TRC(a) a

#define TRC1(a)
//#define TRC1(a) TRC(a)

long long n,s,a[1000000];

int main()
{
	//freopen("output.txt", "w", stdout);

	TRC1
	(
		int q = 100;
		for (int j = 0; j < q; j++)
		{
			ofstream myfile;
			myfile.open("input.txt");
			int m = 1;
			myfile << m << endl;

			for (int k = 0; k < q; k++)
			{
				//myfile << rand() % 20000 - 10000 << " ";
				//myfile << rand() % 10000  << " ";
				myfile << -(rand() % 10000 )<< " ";
			}
			myfile.close();

			FILE *fr1 = freopen("input.txt", "r", stdin);

			fclose(fr1);

	)
	//FILE *fr2 = freopen("input.txt", "r", stdin);

	cin >> n >> s;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	long long x=0, y=0;
	for (int i = 0; i < n/2; i++)
	{
		if (a[i] > s) x += a[i] - s;
		if (a[n - 1 - i] < s) x += s - a[n - 1 - i];
	}
	cout << x + y + abs(a[n / 2] - s);
	//fclose(fr2);

	TRC1
	(
		if (maxL+1 != L || maxR+1 != R || mx != max)
		{
			break;
		}
		}
	)

}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <list>
#include <sstream>
#include <vector>
#include <clocale>
#include <stdlib.h>
#include <queue>
#include <fstream>

using namespace std;

//#define TRC(a)
#define TRC(a) a

#define TRC1(a)
//#define TRC1(a) TRC(a)

int n,s,a[1000000];

int main()
{
	freopen("output.txt", "w", stdout);

	TRC1
	(
		int q = 100;
		for (int j = 0; j < q; j++)
		{
			ofstream myfile;
			myfile.open("input.txt");
			int m = 1;
			myfile << m << endl;

			for (int k = 0; k < q; k++)
			{
				//myfile << rand() % 20000 - 10000 << " ";
				//myfile << rand() % 10000  << " ";
				myfile << -(rand() % 10000 )<< " ";
			}
			myfile.close();

			FILE *fr1 = freopen("input.txt", "r", stdin);

			fclose(fr1);

	)
	//FILE *fr2 = freopen("input.txt", "r", stdin);

	cin >> n >> s;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int x=0, y=0;
	for (int i = 0; i < n/2; i++)
	{
		if (a[i] > s) x += a[i] - s;
		if (a[n - 1 - i] < s) x += s - a[n - 1 - i];
	}
	cout << x + y + abs(a[n / 2] - s);
	//fclose(fr2);

	TRC1
	(
		if (maxL+1 != L || maxR+1 != R || mx != max)
		{
			break;
		}
		}
	)

}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <list>
#include <sstream>
#include <vector>
#include <clocale>
#include <stdlib.h>
#include <queue>
#include <fstream>

using namespace std;

//#define TRC(a)
#define TRC(a) a

#define TRC1(a)
//#define TRC1(a) TRC(a)

int n,s,a[1000000];

int main()
{
	freopen("output.txt", "w", stdout);

	TRC1
	(
		int q = 100;
		for (int j = 0; j < q; j++)
		{
			ofstream myfile;
			myfile.open("input.txt");
			int m = 1;
			myfile << m << endl;

			for (int k = 0; k < q; k++)
			{
				//myfile << rand() % 20000 - 10000 << " ";
				//myfile << rand() % 10000  << " ";
				myfile << -(rand() % 10000 )<< " ";
			}
			myfile.close();

			FILE *fr1 = freopen("input.txt", "r", stdin);

			fclose(fr1);

	)
	FILE *fr2 = freopen("input.txt", "r", stdin);

	cin >> n >> s;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int x=0, y=0;
	for (int i = 0; i < n/2; i++)
	{
		if (a[i] > s) x += a[i] - s;
		if (a[n - 1 - i] < s) x += s - a[n - 1 - i];
	}
	cout << x + y + abs(a[n / 2] - s);
	fclose(fr2);

	TRC1
	(
		if (maxL+1 != L || maxR+1 != R || mx != max)
		{
			break;
		}
		}
	)

}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <list>
#include <sstream>
#include <vector>
#include <clocale>
#include <stdlib.h>
#include <queue>
#include <fstream>

using namespace std;

//#define TRC(a)
#define TRC(a) a

#define TRC1(a)
//#define TRC1(a) TRC(a)

int n,s,a[1000000];

int main()
{
	//freopen("output.txt", "w", stdout);

	TRC1
	(
		int q = 100;
		for (int j = 0; j < q; j++)
		{
			ofstream myfile;
			myfile.open("input.txt");
			int m = 1;
			myfile << m << endl;

			for (int k = 0; k < q; k++)
			{
				//myfile << rand() % 20000 - 10000 << " ";
				//myfile << rand() % 10000  << " ";
				myfile << -(rand() % 10000 )<< " ";
			}
			myfile.close();

			FILE *fr1 = freopen("input.txt", "r", stdin);

			fclose(fr1);

	)
	//FILE *fr2 = freopen("input.txt", "r", stdin);

	cin >> n >> s;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int x=0, y=0;
	for (int i = 0; i < n/2; i++)
	{
		if (a[i] > s) x += a[i] - s;
		if (a[n - 1 - i] < s) x += s - a[n - 1 - i];
	}
	cout << x + y + abs(a[n / 2] - s);
	//fclose(fr2);

	TRC1
	(
		if (maxL+1 != L || maxR+1 != R || mx != max)
		{
			break;
		}
		}
	)

}


#pragma comment(linker, "/STACK:436777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
//stack<pair<int, int> > s;

int main()
{
	int const sz = 5e5+10;
	ll i, j, n, k, a[sz + 1], r[sz + 1];//suma[sz+1],sumb[sz+1];
	ll suma, sumb, sum = 0,s;

	cin >> n>>s;

	rep(i, 1, n) cin >> a[i];

	sort(a + 1, a + n + 1);

	ll l = 0, m = 0,ans=0;

	rep(i, 1, n)
	{
		if (a[i] > s) m++;
		if (a[i] < s) l++;
	}

	if (l >= (n + 1) / 2)
	{
		rep(i, (n + 1) / 2, n) if (a[i] < s) { ans += abs(a[i] - s); }
	}
	else
	if (m >= (n + 1) / 2)
	{
		brep(i, (n + 1) / 2, 1) if (a[i] > s) { ans += abs(a[i] - s); }
	}

	cout<<ans;

	return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
//#include <stdio.h>

using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

long long mod = /*27449*/1e9 + 9;
int inf = 1e9;
double eps = 1e-2;

ifstream in("input.txt");
ofstream out("output.txt");

int main()
{
	int n, s;
	cin >> n >> s;
	vector <int> a;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
	}

	sort(a.begin(), a.end());
	long long ans = 0;
	if (a[n / 2] < s)
	{
		for (int i = n / 2; i < n; i++)
		{
			if (a[i] >= s) break;
			ans += s - a[i];
		}
	}
	else
	{
		for (int i = n / 2; i >= 0; i--)
		{
			if (a[i] <= s) break;
			ans += a[i] - s;
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n = 0, m = 0, l = 0;
    long long k = 0;
    cin >> n >> m;
    vector<int> buf(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> buf[i];
    }
    sort(buf.begin(), buf.end());
    l = n / 2;
    if (buf[l] == m) {
        cout << 0;
        return 0;
    }
    if (buf[l] < m) {
        for (int i = l; i < n; i++) {
            if (buf[i] < m) {
                k += m - buf[i];
            }
            else {
                break;
            }
        }
    }
    else {
        for (int i = l; i > -1; i--) {
            if (buf[i] > m) {
                k += buf[i] - m;
            }
            else {
                break;
            }
        }
    }
    cout << k;
}


n, s = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
m = n // 2
me = a[m]
ct = m
if me == s:
    print(0)
    exit(0)
elif me < s:
    while ct < n and a[ct] < s:
        ct += 1
    ds = abs(sum([x for x in a[m:ct:1]]) - (ct-m)*s)
elif me > s:
    while ct >= 0 and a[ct] > s:
        ct -= 1
    ds = abs(sum([(x-s) for x in a[ct+1:m+1:1]]) - (m-ct)*s)
print(abs(ds))