#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("castel.in");
ofstream fout("castel.out");
struct acces
{
int cam,ch;
} ca[155][155],act;
int n,m,i,j,nr,k;
int q[2][25000],v[25000],viz[25000];
void cautare(int x,int y)
{
int i,l,c,l1,c1,p,u;
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
p=u=1;
q[0][p]=x;
q[1][p]=y;
while(p<=u)
{
l=q[0][p];
c=q[1][p];
for(i=0;i<4;i++)
{
l1=l+dx[i];
c1=c+dy[i];
if(l1>=1 && c1>=1 && l1<=m && c1<=n)
if(v[ca[l1][c1].ch]==1)
{
q[0][++u]=l1;
q[1][u]=c1;
v[ca[l1][c1].cam]=1;
if(viz[ca[l1][c1].cam]==0)
{
viz[ca[l1][c1].cam]=1;
nr++;
}
}
}
p++;
}
}
int main()
{
fin>>m>>n>>k;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
nr=j+(i-1)*n;
fin>>ca[i][j].ch;
ca[i][j].cam=nr;
if(nr==k)
{
q[0][1]=i;
q[1][1]=j;
v[nr]=1;
v[ca[i][j].ch]=1;
}
}
nr=0;
i=q[0][1];
j=q[1][1];
cautare(i,j);
fout<<nr;
return 0;
}