public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int m = s.nextInt();
int n = s.nextInt();
int[][] arr = new int[m][n];
// taking input
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
arr[i][j] = s.nextInt();
}
} // end
int k = s.nextInt();
System.out.println(searchMatrix(arr, m, n, k));
s.close();
}
private static int searchMatrix(int[][] arr, int m, int n, int k) {
// TODO Auto-generated method stub
int l=0, r=m-1;
while(l <n && r>=0) {
if(arr[l][r] == k ) {
return 1;
}
if(arr[l][r] > k) {
r--;
}
else {
l++;
}
}
return 0;
}