#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
int mat[N][N];
int search2(int m, int n, int x)
{
int smallest = mat[0][0], largest = mat[n - 1][n - 1];
if (x < smallest || x > largest)
return 0;
int i = 0, j = n - 1;
while (i < n && j >= 0)
{
if (mat[i][j] == x)
{
return 1;
}
if (mat[i][j] > x)
j--;
else
i++;
}
return 0;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> mat[i][j];
}
}
int x;
cin >> x;
cout << search2(m, n, x);
return 0;
}