#include <cstdio>
#include <queue>
#include <cstring>
int n, m, x, cnt = 0;
int G[5050][5050], dist[5050];
std::queue<int> Q, Q2;

int main(int argc, char *argv[])
{
    FILE *fp1 = fopen(argv[1],"r");
    FILE *fp2 = fopen(argv[2],"r");
    fscanf(fp1, "%d%d", &n, &m);
    for(int i = 0 ; i < m ; i++ )
    {
        int a, b;
        fscanf(fp1, "%d%d", &a, &b);
        G[a][b] = true;
    }
    for(int i = 1 ; i <= n ; i++ )
        for(int j = 1 ; j <= n ; j++ )
            G[n+1][i] += G[j][i];
    while( fscanf(fp2,"%d", &x) != EOF )
    {
        if( G[n+1][x] > 0 )
        {
            printf("0");
            return 0;
        }
        for(int i = 1 ; i <= n ; i++ )
            if( G[x][i] == 1 ) G[x][i] = 0, G[n+1][i]--;
        cnt++;
    }
    if( cnt != n ) printf("0");
    else printf("1");
}
/*
7 9
1 2
1 3
1 4
2 7
3 5
2 6
4 6
5 6
6 7

9 11
1 2
1 3
1 4
2 5
3 5
4 6
5 7
5 8
6 8
7 9
8 9

11 13
10 2
1 2
1 3
1 4
2 5
3 5
4 6
5 7
5 8
6 8
7 9
8 9
7 11

11 14
10 2
1 2
1 3
1 4
2 5
3 5
4 6
5 7
5 8
6 8
7 9
8 9
7 11
11 5
*/
