#include <iostream>

using namespace std;

int main()
{
    int n, m, pr = 0, br1 = 0;
    cin >> n >> m;

    for (int i = 0; i < n * m; i++) {
        int br;
        cin >> br;
        if (pr == 0) {
            br1 = br;
            pr = 1;
        }
    }

    if (br1 == 1) {
        cout << 1;
    } else {
        cout << 0;
    }

    return 0;
}