#include <bits/stdc++.h>
#define maxn 1003
using namespace std;

int n,m;
int a[maxn];
int b[maxn];
int dp[maxn][maxn];

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 1 ; i <= n ; i++ )
		scanf("%d",&a[i]);
	for( int j = 1 ; j <= m ; j++ )
		scanf("%d",&b[j]);
	for( int i = 0 ; i <= n ; i++ )
		for( int j = 0 ; j <= m ; j++ )
			if(i+j) {
				dp[i][j] = INT_MAX;
				if(i)
					dp[i][j] = min(dp[i][j],dp[i-1][j]+1);
				if(j)
					dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
				if(i && j)
					dp[i][j] = min(dp[i][j],dp[i-1][j-1]+(a[i]!=b[j]));
			}
	printf("%d\n",dp[n][m]);
	return 0;
}
 #include<bits/stdc++.h> 
using namespace std;
namespace Sakurajima_Mai{
	#define ms(a) memset(a,0,sizeof(a))
	#define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
	#define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
	#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
	#define ce(i,r) i==r?'\n':' '
	#define pb push_back 
	#define all(x) x.begin(),x.end()
	#define gmn(a,b) a=min(a,b)
	#define gmx(a,b) a=max(a,b)
	#define fi first
	#define se second   					  
	typedef long long ll;
	typedef unsigned long long ull;
	typedef double db;
	const int infi=1e9;
	const ll infl=4e18;
	inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
	//std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
	inline int qi(){
	    int f=0,fu=1; char c=getchar();
	    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
	    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
	    return f*fu;
	}
	inline ll ql(){
		ll f=0;int fu=1; char c=getchar();
	    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
	    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
	    return f*fu;
	}
	inline db qd(){
	    char c=getchar();int flag=1;double ans=0;
	    while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
	    if(c=='-') flag=-1,c=getchar();
	    while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
	    if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
	    return ans*flag;
	}
}
namespace Read{
	#define si(a) scanf("%d",&a)
	#define sl(a) scanf("%lld",&a)
	#define sd(a) scanf("%lf",&a)
	#define ss(a) scanf("%s",a)
	#define rai(x,a,b) repi(i,a,b) x[i]=qi()
	#define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
	#define pi(x) printf("%d",x)
	#define pl(x) printf("%lld",x)
	#define ps(x) printf("%s",x)
	#define pc(x) printf("%c",x)
	#define pe() puts("")
}
namespace DeBug{
	#define MARK false
	#define DB if(MARK) 
	#define pr(x) cout<<#x<<": "<<x<<endl
	#define pra(x,a,b) cout<<#x<<": "<<endl; \
			repi(i,a,b) cout<<x[i]<<" ";	 \
			puts("");   
	#define FR(a) freopen(a,"r",stdin)
	#define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
const int MAX_N=1e5+5;
const int MAX_E=1e5+5;
typedef pair<int,int> P;
struct Edge{int to,nxt;int w;}e[MAX_E<<1];
int head[MAX_N],tote;
void add_edge(int u,int v,int w){e[++tote].to=v,e[tote].w=w,e[tote].nxt=head[u];head[u]=tote;}
int V;//点总数，下标1开始
int dis[MAX_N];
void dijkstra(int s)
{
	repi(i,1,V) dis[i]=infi;
	priority_queue<P,vector<P>,greater<P> > q;
	dis[s]=0,q.push(P(0,s));
	while(!q.empty())
	{
		P now=q.top(); q.pop();
		int u=now.se;
		if(dis[u]<now.fi)	continue;
		reps(u)if(dis[v]>dis[u]+e[i].w) dis[v]=dis[u]+e[i].w,q.push(P(dis[v],v));	
	}	
}

int k,c[17],g[17][17];
int dp[(1<<17)-1+5][17];
void init(int n)
{
	repi(i,0,n) head[i]=0;
	V=n,tote=0;
}
int main()
{
	int n=qi(),m=qi(); init(n);
	repi(i,1,m){
		int u=qi(),v=qi();
		add_edge(u,v,1),add_edge(v,u,1);
	}
	k=qi(); rai(c,0,k-1);
	repi(i,0,k-1){
		dijkstra(c[i]);
		repi(j,0,k-1) g[i][j]=dis[c[j]];
	}
	repi(i,0,(1<<k)-1)repi(j,0,k-1) dp[i][j]=infi;
	repi(i,0,k-1) dp[1<<i][i]=1;
	repi(i,0,(1<<k)-1)repi(j,0,k-1)if(dp[i][j]!=infi){
		repi(nxt,0,k-1) gmn(dp[i|(1<<nxt)][nxt],dp[i][j]+g[j][nxt]);
	}	
	int ans=infi;
	repi(i,0,k-1) gmn(ans,dp[(1<<k)-1][i]);
	if(ans==infi) ans=-1;
	pi(ans),pe();
	return 0;
}