#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;

map<int, int> my[maxn];

map<int, int> player[maxn];

int main(int argc, char *argv[])
{
    registerTestlibCmd(argc, argv);

    int jans = ans.readInt();

    if (jans == -1)
    {
        int pans = ouf.readInt();
        if (pans != -1)
            quitf(_wa, "should be -1");
    }
    else
    {
        int n = inf.readInt();
        int m = inf.readInt();

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                my[i][j] = inf.readInt();
                player[i][j] = ouf.readInt(0, 15);
                if (my[i][j] == 0 || __builtin_popcount(my[i][j]) != 2)
                {
                    if (my[i][j] != player[i][j])
                        quitf(_wa, "constraints not satisfied on point (%d ,%d)", i + 1, j + 1);
                }
                else if (my[i][j] == 5 || my[i][j] == 10)
                {
                    if (!(player[i][j] == 5 || player[i][j] == 10))
                        quitf(_wa, "constraints not satisfied on point (%d ,%d)", i + 1, j + 1);
                }
                else if (player[i][j] == 5 || player[i][j] == 10 || __builtin_popcount(player[i][j]) != 2)
                {
                    quitf(_wa, "constraints not satisfied on point (%d ,%d)", i + 1, j + 1);
                }
            }
        }

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                if (i == 0 && (player[i][j] & 1))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (j == m - 1 && (player[i][j] & 2))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (i == n - 1 && (player[i][j] & 4))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (j == 0 && (player[i][j] & 8))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (i != 0 && (bool)(player[i][j] & 1) != (bool)(player[i - 1][j] & 4))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (j != m - 1 && (bool)(player[i][j] & 2) != (bool)(player[i][j + 1] & 8))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (i != n - 1 && (bool)(player[i][j] & 4) != (bool)(player[i + 1][j] & 1))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
                if (j != 0 && (bool)(player[i][j] & 8) != (bool)(player[i][j - 1] & 2))
                    quitf(_wa, "constraints not satisfied near point (%d ,%d)", i + 1, j + 1);
            }
        }
    }

    quitf(_ok, "correct");
}