#include
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int a[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int x;
cin>>x;
int r=0,c=m-1;
if(n==0&&m==0){
cout<<“0”;
return 1;
}
if(x<a[0][0]&& x>a[n-1][m-1]){
cout<<“0”;
return 1;
}
int count=0;
while(r<n && c>=0){
if(x>a[r][c]){
r++;
}else if(x<a[r][c]){
c–;
}else if(a[r][c]==x){
count=1;
break;
}
}
if(count==0){
cout<<“0”;
}else{
cout<<“1”;
}
return 0;
}