import ru.ifmo.testlib.*;
import ru.ifmo.testlib.Outcome.Type;

public class Check implements Checker {

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		long ansJury = ans.nextLong();
		long ansPart = ouf.nextLong();
		
		if (ansJury < ansPart) {
			return new Outcome(Type.WA, "Jury found better answer");
		}
		
		Task[] t = readTasks(inf);
		int[] order = readOrder(t.length, ouf);
		if (!isPermutation(order)) {
			return new Outcome(Type.WA, "Given order is not a permutation of {1..n}");
		}
		if (ansPart != getAns(t, order)) {
			return new Outcome(Type.WA, "Given order is inconsistent with given answer");
		}
		
		if (ansPart < ansJury) {
			return new Outcome(Type.FAIL, "Participant found better answer");
		}
		
		return new Outcome(Type.OK, "Ok");
	}

	class Task {
		int pain, suffering;
		int id;
		public Task(int pain, int suffering, int id) {
			super();
			this.pain = pain;
			this.suffering = suffering;
			this.id = id;
		}
	}
	
	long getAns(Task[] tasks, int[] order) {
		int maxPain = 0, maxSuffering = 0;
		long result = 0;
		for (int i : order) {
			Task t = tasks[i];
			
			if (t.pain > maxPain) {
				result += t.pain;
				maxPain = t.pain;
			}
			
			if (t.suffering > maxSuffering) {
				result += t.suffering;
				maxSuffering = t.suffering;
			}
		}
		return result;
	}
	
	Task[] readTasks(InStream in) {
		int n = in.nextInt();
		Task[] t = new Task[n];
		for (int i = 0; i < n; i++) {
			t[i] = new Task(in.nextInt(), in.nextInt(), i);
		}
		return t;
	}

	
	int[] readOrder(int size, InStream ans) {
		int[] order = new int[size];
		for (int i = 0; i < size; i++) {
			order[i] = ans.nextInt() - 1;
		}
		return order;
	}
	
	boolean isPermutation(int[] order) {
		int n = order.length;
		boolean[] was = new boolean[n];
		for (int i = 0; i < n; i++) {
			if (order[i] < 0 || order[i] > n - 1) {
				return false;
			}
			if (was[order[i]]) {
				return false;
			}
			was[order[i]] = true;
		}
		for (boolean b : was) {
			if (!b) {
				return false;
			}
		}
		return true;
	}
}