{
TASK: move
LANG:PASCAL
}
{$S-}
var conf:Array [1..9] of Byte;
    a:Array [1..9,1..9] of Boolean;
    n,m,i,j,x,y,min,t,p:Longint;
function ok:Boolean;
var i:Byte;
    res:Boolean;
Begin
  res:=True;
 For i:=1 to n do
  If conf[i]<>i then
   Begin
     res:=False;
     Break;
   End;
  ok:=res;
End;
procedure swap(last,pointed:Byte);
var i:Byte;
Begin
 If conf[1]=1 then
 If ok then
 Begin
  If t<min then min:=t;
   Exit;
 End;
 If t>11 then exit;
 For i:=1 to n do
  if (i<>last)and(i<>pointed)and(a[pointed,i]) then
   Begin
     p:=conf[pointed];
     conf[pointed]:=conf[i];
     conf[i]:=p;
     t:=t+1;
     swap(pointed,i);
     t:=t-1;
     p:=conf[pointed];
     conf[pointed]:=conf[i];
     conf[i]:=p;
   End;
End;
Begin
  ReadLn(n,m);
 For i:=1 to m do
 Begin
   ReadLn(x,y);
   a[x,y]:=True;
   a[y,x]:=True;
 End;
 For i:=1 to n do Read(conf[i]);
  min:=2147483647;
  t:=0;
 For i:=1 to n do
  if conf[i]=1 then
  Begin
    swap(i,i);
   If min=2147483647 then WriteLn('-1') else WriteLn(min);
    break;
  End;
End.