/*
TASK: move
LANG: C
*/

#include<stdio.h>

int fuct[16]={0,1,2,6,24,120,720,5040,40320};
int n,m,k=0,h,i,j,e,f;
int a,b;
int num,st;
int v[16][16]={0};
int q[500000];
int used[500000]={0};
int start[16],tmp[16],got[16];

int main () {
    freopen("test.txt","rt",stdin);
    scanf("%d %d",&n,&m);
    for (i=0;i<m;i++) {
        scanf("%d %d",&a,&b);
        v[a-1][b-1]=v[b-1][a-1]=1;
        }
    for (i=0;i<n;i++) {
        scanf("%d",&start[i]);
        start[i]--;
        }
    //code
    a=0;
    for (i=0;i<n;i++) tmp[i]=0;
    for (i=0;i<n;i++) {
        b=0;
        for (j=0;j<start[i];j++)
            if (!tmp[j]) b++;
        a+=b*fuct[n-i-1];
        tmp[start[i]]=1;
        }
    //
    used[a]=1;
    q[0]=a;
    k=1;
    for (h=0;h<k;h++) {

        //decode
        num=q[h];
        for (i=0;i<n;i++) got[i]=0;
        for (i=0;i<n-1;i++) {
            st=fuct[n-i-1];
            a=num/st;
            num%=st;
            j=0;
            b=0;
            while (j<a) {
                  if (!got[b]) j++;
                  b++;
                  }
            start[i]=b;
            got[b]=1;
            tmp[b]=i;
            }
        //
        j=0;
        while (got[j]) j++;
        start[i]=j;
        tmp[j]=i;
        
        for (i=0;i<n;i++)
            if (!start[i]) break;
        
        for (j=0;j<n;j++)
            if (v[i][j]) {
                         a=start[i];
                         start[i]=start[j];
                         start[j]=a;
                         //code
                         a=0;
                         for (e=0;e<n;e++) got[e]=0;
                         for (e=0;e<n;e++) {
                             b=0;
                             for (f=0;f<start[e];f++)
                                 if (!got[f]) b++;
                             a+=b*fuct[n-e-1];
                             got[start[e]]=1;
                             }
                         //
                         if (!used[a]) {
                                       q[k++]=a;
                                       if (!a) {
                                               printf("%d\n",used[q[h]]);
                                               return 0;
                                               }
                                       used[a]=used[q[h]]+1;
                                       }
                         a=start[i];
                         start[i]=start[j];
                         start[j]=a;
                         }
        }
    printf("-1\n");
    return 0;
    }
