uses
    testlib, sysutils;

var
    ja, pa, n, i, j, a, b, mode: longint;
    sum, l, r : array[1..50000] of longint;
    alive : array[1..50000] of boolean;
begin
    ja := ans.readlongint;
    pa := ouf.readlongint;

  	if (pa > ja) then quit(_wa, inttostr(ja) + ' expected, ' + inttostr(pa) + ' found');

  	fillchar(alive, sizeOf(alive), 0);
	fillchar(sum, sizeOf(alive), 0);

	n := inf.readlongint;
	for i := 1 to n do begin
		sum[i] := inf.readlongint;
		alive[i] := true;
		l[i] := i;
		r[i] := i;
	end;
	
  	for i := 1 to pa do begin
  		a := ouf.readlongint;
  		b := ouf.readlongint;
  		if (not (alive[a] and alive[b])) then quit(_wa, 'Illegal operation (Dead heaps used) ' + inttostr(a) + ' ' + inttostr(b) + ' at line ' + inttostr(i + 1));
  		alive[a] := false;
  		alive[b] := false;
  		mode := 0;
  		if (((r[a] mod n) + 1) = l[b]) then mode := 1;
  		if (((r[b] mod n) + 1) = l[a]) then mode := 2;
  		if (mode = 0) then quit(_wa, 'Illegal operation (Heaps do not coincide) ' + inttostr(a) + ' ' + inttostr(b) + ' at line ' + inttostr(i + 1));  		
  		sum[n + i] := sum[a] + sum[b];
  		alive[n + i] := true;
  		if (mode = 1) then begin
  			l[n + i] := l[a];
  			r[n + i] := r[b];
  		end else begin
  			l[n + i] := l[b];
  			r[n + i] := r[a];
  		end;
  	end;

  	if not (ouf.seekeof) then quit(_pe, 'Extra lines found');

  	j := -1;
  	for i := 1 to n + pa do begin
  		if (not alive[i]) then continue;
  		if (j < 0) then j := i;
  		if (sum[i] <> sum[j]) then quit(_wa, 'Heaps ' + inttostr(j) + ' and ' + inttostr(i) + ' have different size');
  	end;

  	if (pa < ja) then quit(_fail, 'Participant has a better answer');

    quit(_ok, inttostr(pa));
end.