#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}

int main(){
  int n;
  cin>>n;
  V<int> id(2*n+5,0);
  V<bool> used(2*n+5,0);
  V<int> a(n),b(n);
  V<int> cont(2*n,-1);
  bool ok=true;
  for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
      if(a[i]!=-1){
          a[i]--;
          if(used[a[i]])ok=false;
          used[a[i]]=1;
          id[a[i]]=i+1;
      }
      if(b[i]!=-1){
          b[i]--;
          if(used[b[i]])ok=false;
          used[b[i]]=1;
          id[b[i]]=-(i+1);          
      }
      if(a[i]!=-1&&b[i]!=-1){
          cont[a[i]]=b[i];
          cont[b[i]]=a[i];
      }
  }
  if(!ok){
      cout<<"No"<<"\n";
      return 0;
  }
  V<bool> dp(2*n+1,false);
  dp[0]=true;
  for(int i=0;i<2*n;i++){
      if(!dp[i])continue;
      for(int j=i+1;j<2*n;j++){//i~jを埋める,i~jは対応関係から偶数長
          int d=j-i+1;
          if(d%2==1)continue;
          d/=2;
          bool able=true;
          V<bool> ex(n,false);
          for(int k=0;k<d;k++){
              int l=i+k,r=i+k+d;
              if(cont[l]!=-1&&!(i<=cont[l]&&cont[l]<=j))able=false;
              if(cont[r]!=-1&&!(i<=cont[r]&&cont[r]<=j))able=false;
              if(id[l]!=0&&id[r]!=0){
                  if(id[l]<0||id[l]+id[r]!=0)able=false;
              }
              if(id[l]<0||id[r]>0){
                  able=false;
              }else{
                  if(id[l]!=0){
                      int v=id[l]-1;
                      if(ex[v]){
                          able=false;
                      }
                      ex[v]=true;
                  }
              }
          }
        if(able)dp[j+1]=1;
      }
  }
  cout<<(dp[2*n]?"Yes":"No")<<"\n";
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int tt; cin>>tt; while(tt--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++)
#define for1(i,low,high) for(int i=low;i<high;i++)
#define for2(i,low,high) for(int i=low;i<=high;i++)
#define rev(i,high,low)  for(int i=high;i>=low ;i--)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
void i_o() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
#endif
}
int n,m,k;
vector<vector<int> >g;
vector<int>c;
vector<int>d[20];
int dp[1<<18][20];
void bfs(int i){
	d[i][c[i]]=0;
	queue<int>q;
	q.push(c[i]);
	while(!q.empty()){
		int cur=q.front(); q.pop();
		for(int j:g[cur]){
			if(d[i][j]>d[i][cur]+1){
				if(d[i][j]==1e7) q.push(j);
				d[i][j]=d[i][cur]+1;
			}
		}
	}
}

int fun(int mask,int i){
	if(mask==0)
		return 0;
	if(dp[mask][i]!=-1) return dp[mask][i];
	int ans=1e7;
	if(i==k){
		for(int j=0;j<k;j++){
			ans=min(ans,fun(mask^(1<<j),j)+1);
		}
	}
	else
		for(int j=0;j<k;j++){
			if(!(mask&(1<<j))) continue;
			ans=min(ans,fun(mask^(1<<j),j)+d[j][c[i]]);
		}
	return dp[mask][i]=ans;
}

int main()
{
    boost; i_o();
    cin>>n>>m;
    g.resize(n+1);
    for1(i,0,m){
    	int a,b; cin>>a>>b;
    	g[a].pb(b); g[b].pb(a);
    }
    cin>>k;
	c.resize(k); 
	for1(i,0,k) d[i].resize(n+1,1e7);
    for1(i,0,k) cin>>c[i];
    for1(i,0,k) bfs(i);
  /*  for1(i,0,k){
    	cout<<"src= "<<c[i]<<endl;
    	for1(j,1,n+1) cout<<d[i][j]<<" ";
    	cout<<endl;
    }
    */
    fil(dp,-1);
 /*
    for1(mask,0,(1<<k)) for1(i,0,k+1) dp[mask][i]=1e7;
    for1(i,0,k) dp[1<<i][i]=d[0][i]=0;
    for(int mask=0;mask<(1<<k);mask++){
    	for(int i=0;i<k;i++){
    			if(!(mask&(1<<i))) continue;
    			for(int j=0;j<k;j++){
    				 if(!(mask&(i<<j))) continue;
    				dp[mask][i]=min(dp[mask][i],dp[mask^i][j]+d[c[j]][c[i]]);
    			}
    	}
    }
    */
    int ans=fun((1<<k)-1,k);
    if(ans>=1e7) ans=-1;
    cout<<ans<<endl;
    return 0;
}

