import java.util.;
import java.io.;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] matrix = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
matrix[i][j] = sc.nextInt();
}
}
int target = sc.nextInt();
System.out.println(search2dBinary(matrix, target));
}
static int search2dBinary(int[][] matrix, int target) {
if(matrix.length==0)
return 0;
int r = matrix.length;
if (r == 0) return 0;
int c = matrix[0].length;
int lo = 0;
int high = (r * c) - 1;
while (lo <= high) {
int mid = (lo + (high - lo) / 2);
int midEle = matrix[mid / c][mid % c];
if (midEle == target) {
return 1;
} else if (midEle < target) {
lo = mid + 1;
} else {
high = mid - 1;
}
}
return 0;
}
}