{
TASK:move
LANG:PASCAL
}
program sux;
var a:array[1..10,1..10] of byte;
    b:array[1..10]of byte;
    k,n,m,i,j,l,c,s,z:integer;
begin
 readln(n,m);
 for k:=1 to m do
  begin
   readln(i,j);
   a[i,j]:=1;
  end;
 for k:=1 to n do
  begin
   read(b[k]);
   if b[k]=1 then l:=k;
  end;
  while b[1]<>1 do
  for i:=1 to n do
  if (a[l,i]=1)or(a[i,l]=1) then begin
                                  s:=b[i];
                                  b[i]:=b[l];
                                  b[l]:=s;
                                  l:=i;
                                  inc(z);
                                  break;
                                 end
  else continue;
 for k:=1 to n do
   if b[k]=k then inc(c);
if c=n then  writeln(z)
else writeln(-1);
end.
