import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;
import static ru.ifmo.testlib.Outcome.Type.*;

import java.util.Arrays;

public class Check implements Checker {
    public Outcome outcome(Outcome.Type type, final String format, final Object... args) {
        return new Outcome(type, String.format(format, args));
    }

    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int m = inf.nextInt();

        int[][] pField = new int[n][m];
        pField[0][0] = ouf.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (pField[0][0] != -1 && (i > 0 || j > 0)) {
                    pField[i][j] = ouf.nextInt();
                }
            }   
        }

        int[][] jField = new int[n][m];
        jField[0][0] = ans.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (jField[0][0] != -1 && (i > 0 || j > 0)) {
                    jField[i][j] = ans.nextInt();
                }
            }
        }

        int pAns = check(pField);
        int jAns = check(jField);

        if (jAns == 0) {
            return outcome(FAIL, "Jury has wrong answer");
        }
        if (pAns == 0) {
            return outcome(WA, "Participant has wrong answer");
        }

        if (jAns == -1 && pAns == 1) {
            return outcome(FAIL, "Participant found answer, but jury don't");
        }
        if (jAns == 1 && pAns == -1) {
            return outcome(WA, "Jury found answer, but participant don't");
        }
        return outcome(OK, "Corrent answer");
    }

    public int check(int[][] field) {
        if (field[0][0] == -1) {
            return -1;
        }
        int n = field.length;
        int m = field[0].length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (1 > field[i][j] || field[i][j] > 5) {
                    return 0;
                }
            }
        }
        for (int i = 0; i <= n - 3; i++) {
            for (int j = 0; j <= m - 3; j++) {
                int[] colors = new int[5];
                int size = 0;
                colors[size++] = field[i][j + 1];
                colors[size++] = field[i + 1][j];
                colors[size++] = field[i + 1][j + 1];
                colors[size++] = field[i + 1][j + 2];
                colors[size++] = field[i + 2][j + 1];
                Arrays.sort(colors);
                boolean fail = false;
                for (int it = 0; it < size - 1; it++) {
                    if (colors[it] == colors[it + 1]) {
                        fail = true;
                    }
                }
                if (fail) {
                    return 0;
                }

                colors = new int[8];
                size = 0;
                colors[size++] = field[i][j];
                colors[size++] = field[i][j + 1];
                colors[size++] = field[i][j + 2];
                colors[size++] = field[i + 1][j];
                colors[size++] = field[i + 1][j + 2];
                colors[size++] = field[i + 2][j];
                colors[size++] = field[i + 2][j + 1];
                colors[size++] = field[i + 2][j + 2];
                Arrays.sort(colors);
                int differentColors = 0;
                for (int it = 0; it < size;) {
                    differentColors++;
                    while (it < size - 1 && colors[it] == colors[it + 1]) {
                        it++;
                    }
                    it++;
                }
                if (differentColors > 4) {
                    return 0;
                }
            }                                 
        }
        return 1;
    }
}
