#include <iostream>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
double M[m][n];
bool monotone[m];
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
cin >> M[i][j];
for (int i = 0; i < m; i++) {
bool check = true, diff;
if (M[i][0] != M[i][1]) {
diff = (M[i][1] > M[i][0]);
for (int j = 2; j < n; j++)
if ((M[i][j] == M[i][j-1]) || ((M[i][j] > M[i][j-1]) != diff)) {
check = false;
break;
}
}
else
check = false;
monotone[i] = check;
}
for (int i = 0; i < m; i++)
cout << monotone[i] << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbSwgbjsKCWNpbiA+PiBtID4+IG47Cglkb3VibGUgTVttXVtuXTsKCWJvb2wgbW9ub3RvbmVbbV07CgkKCWZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKQoJCWZvciAoaW50IGogPSAwOyBqIDwgbjsgaisrKQoJCQljaW4gPj4gTVtpXVtqXTsKCQkJCglmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgewoJCWJvb2wgY2hlY2sgPSB0cnVlLCBkaWZmOwoJCWlmIChNW2ldWzBdICE9IE1baV1bMV0pIHsKCQkJZGlmZiA9IChNW2ldWzFdID4gTVtpXVswXSk7CgkJCWZvciAoaW50IGogPSAyOyBqIDwgbjsgaisrKQoJCQkJaWYgKChNW2ldW2pdID09IE1baV1bai0xXSkgfHwgKChNW2ldW2pdID4gTVtpXVtqLTFdKSAhPSBkaWZmKSkgewoJCQkJCWNoZWNrID0gZmFsc2U7CgkJCQkJYnJlYWs7CgkJCQl9CgkJfQoJCWVsc2UKCQkJY2hlY2sgPSBmYWxzZTsKCQltb25vdG9uZVtpXSA9IGNoZWNrOwoJfQoJCglmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykKCQljb3V0IDw8IG1vbm90b25lW2ldIDw8IGVuZGw7CglyZXR1cm4gMDsKfQ==