public class SearchInMatrix {
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 <= r) {
int mid = l + (r-l)/2;
if(k >= arr[mid][0] && k <= arr[mid][n-1]) {
return binarySearch(arr[mid], n,k);
}
if(k < arr[mid][0]) {
r = mid-1;
}
else {
l = mid+1;
}
}
return 0;
}
private static int binarySearch(int[] arr, int n, int k) {
// TODO Auto-generated method stub
int l=0, r=n-1;
while(l <= r) {
int mid = l + (r-l)/2;
if(arr[mid] == k) {
return 1;
}
if(k < arr[mid]) {
r = mid -1;
}else {
l = mid +1;
}
}
return 0;
}
}