#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

int n, a[300], f[300], id[300], x[300], y[300], cnt[300];
bool valid(int l, int len) {
    for (int i = 1; i <= n / 2; ++i) {
        if (x[i] != -1 && y[i] != -1) {
            if (x[i] >= l + 2 * len) continue;
            if (y[i] < l) continue;
            if (x[i] >= (l + len)) return false;
            if (x[i] < l) return false;
            if (((y[i] - x[i]) != len)) return false;
        } else if (x[i] == -1) {
            if (y[i] >= (l + 2 * len)) continue;
            if (y[i] < l) continue;
            if (y[i] < l + len) return false;
            if (a[y[i] - len]) return false;
        } else if (y[i] == -1) {
            if (x[i] < l) continue;
            if (x[i] >= l + 2 * len) continue;
            if (x[i] >= l + len) return false;
            if (a[x[i] + len]) return false;
        }
    }
    return true;
}
signed main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d %d", &x[i], &y[i]);
        if(x[i] != -1 && y[i] != -1 && x[i] >= y[i]) return puts("No"), 0;
        ~x[i] ? a[x[i]] = 1, cnt[x[i]]++, id[x[i]] = i : 0;
        ~y[i] ? a[y[i]] = 1, cnt[y[i]]++, id[y[i]] = i : 0;
    }
    n <<= 1, f[0] = 1;
    for(int i = 1; i <= n; i++) if(cnt[i] > 1) return puts("No"), 0;
    for(int i = 0; i <= n; i++) if(f[i])
        for(int j = 1; i + 2 * j <= n; j++)
            f[i + 2 * j] |= valid(i + 1, j);
    puts(f[n] ? "Yes" : "No");
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
}
#include<bits/stdc++.h>
#define int long long
#define all(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define EB emplace_back
#define PB push_back
#define PP pop_back
#define MP make_pair
#define F first
#define S second
#define de(x) if(x && x == MODE)
#define MODE 0

using namespace std;

typedef pair<int, int> pii;
const int INF = 1e18;
const int maxn = 1e5 + 7;

vector<int> G[maxn];

int A[maxn], B[maxn];
int C[maxn];
int target[maxn] = {};
bool v[maxn] = {};
int d[20][20] = {};
int dp[1<<20][20] = {};

int32_t main() {
    int i,j;
    int N, M;

    cin >> N >> M;
    for (int i=1; i<=M; i++)
        scanf("%lld %lld", &A[i], &B[i]);
    for (int i=1; i<=M; i++) {
        G[A[i]].PB(B[i]);
        G[B[i]].PB(A[i]);
    }
    int K;
    cin >> K;
    memset(target, -1, sizeof(target));
    for (int i=0; i<K; i++) {
        scanf("%lld", &C[i]);
        target[C[i]] = i;
    }

    for (int i=0; i<K; i++) {
        memset(v, 0, sizeof(v));
        queue<int> que;
        que.push(C[i]);
        v[C[i]] = 1;
        int step = 1;
        while (!que.empty()) {
            int goal = que.size();
            while (goal--) {
                int x = que.front();
                que.pop();
                for (auto y : G[x]) {
                    if (v[y])
                        continue;
                    v[y] = 1;
                    que.push(y);
                    if (target[y] != -1) {
                        d[i][target[y]] = step;
                    }
                }
            }
            step++;
        }
    }

    de(1) {
        for (int i=0; i<K; i++) {
            for (int j=0; j<K; j++) {
                printf("d(%lld, %lld) = %lld\n", i, j, d[i][j]);
            }
        }
    }

    for (int i=0; i<(1<<K); i++) {
        for (int j=0; j<K; j++)
            dp[i][j] = INF;
    }
    for (int i=0; i<K; i++)
        dp[1<<i][i] = 1;
    for (int i=0; i<(1<<K); i++) {
        for (int j=0; j<K; j++) {
            if (i&(1<<j)) {
                for (int k=0; k<K; k++) {
                    if (j == k || !d[j][k])
                        continue;
                    dp[i][j] = min(dp[i][j], dp[i^(1<<j)][k] + d[k][j]);
                    de(1) printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
                }
            }
        }
    }

    int ans = INF;
    for (int i=0; i<K; i++)
        ans = min(ans, dp[(1<<K)-1][i]);
    if (ans == INF)
        printf("-1\n");
    else
        printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//
