import java.util.Arrays;

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

public class Check implements Checker {

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		int n = inf.nextInt(), k = inf.nextInt();
		int[][] a = new int[n][k];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				a[i][j] = inf.nextInt();
			}
		}

		int first = ouf.nextInt();
		if (first == -1) {
			if (ans.nextInt() == -1) {
				return new Outcome(Type.OK, "OK, -1");
			}
			return new Outcome(Type.WA,
					"Participant didn't find answer, but it exists");
		}

		int[] perm = new int[k];
		perm[0] = first - 1;
		for (int i = 1; i < k; i++) {
			perm[i] = ouf.nextInt() - 1;
		}

		int[] t = perm.clone();
		Arrays.sort(t);
		for (int i = 0; i < k; i++) {
			if (t[i] != i) {
				return new Outcome(Type.WA, "Output is not a permutation");
			}
		}

		boolean out = check(perm, a, 0, 0, n);
		if (!out) {
			return new Outcome(Type.WA, "Table is not sorted by this permutation");
		}
		
		if (out == true && ans.nextInt() == -1) {
			return new Outcome(Type.FAIL,
					"Participant found answer, but author didn't");
		}

		return new Outcome(Type.OK, "OK");
	}

	private boolean check(int[] perm, int[][] a, int pos, int l, int r) {
		if (pos == a[0].length || l + 1 == r) {
			return true;
		}

		int col = perm[pos];

		for (int i = l; i < r;) {
			int j = i;
			while (j < r && a[i][col] == a[j][col]) {
				j++;
			}

			if (j < r && a[j - 1][col] > a[j][col]) {
				return false;
			}
			boolean ok = check(perm, a, pos + 1, i, j);
			if (!ok) {
				return false;
			}

			i = j;
		}
		return true;
	}

}
