#include <bits/stdc++.h>
using namespace std;
bool flag[1005][1005];
int cnt[1005],ara[1005];
vector <int> edges[1005];
multiset <int> indeg;
multiset <int>:: iterator it;
int main ()
{
int i,u,v,m,n,t,j,s;
bool chk=true;
scanf ("%d %d",&n,&m);
for (i=0;i<m;i++) {
scanf ("%d %d",&u,&v);
if (!flag[u][v]) {
edges[u].push_back(v);
cnt[v]++;
flag[u][v]=true;
}
if (flag[v][u]) chk=false;
}
for (i=1;i<=n;i++) indeg.insert(cnt[i]);
for (i=1;i<=n;i++) scanf ("%d",&ara[i]);
if (chk) for (i=1;i<=n;i++) {
u=ara[i];
it=indeg.begin();
if (cnt[u]!=*it) {
chk=false;
break;
}
indeg.erase(it);
t=edges[u].size();
for (j=0;j<t;j++) {
v=edges[u][j];
indeg.erase(cnt[v]);
cnt[v]--;
indeg.insert(cnt[v]);
}
}
if (chk) cout<<"YES";
else cout<<"NO";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpib29sIGZsYWdbMTAwNV1bMTAwNV07CmludCBjbnRbMTAwNV0sYXJhWzEwMDVdOwp2ZWN0b3IgPGludD4gZWRnZXNbMTAwNV07Cm11bHRpc2V0IDxpbnQ+IGluZGVnOwptdWx0aXNldCA8aW50Pjo6IGl0ZXJhdG9yIGl0OwppbnQgbWFpbiAoKQp7CiAgICBpbnQgaSx1LHYsbSxuLHQsaixzOwogICAgYm9vbCBjaGs9dHJ1ZTsKCiAgICBzY2FuZiAoIiVkICVkIiwmbiwmbSk7CiAgICBmb3IgKGk9MDtpPG07aSsrKSB7CiAgICAgICAgc2NhbmYgKCIlZCAlZCIsJnUsJnYpOwogICAgICAgIGlmICghZmxhZ1t1XVt2XSkgewogICAgICAgICAgICBlZGdlc1t1XS5wdXNoX2JhY2sodik7CiAgICAgICAgICAgIGNudFt2XSsrOwogICAgICAgICAgICBmbGFnW3VdW3ZdPXRydWU7CiAgICAgICAgfQogICAgICAgIGlmIChmbGFnW3ZdW3VdKSBjaGs9ZmFsc2U7CiAgICB9CiAgICBmb3IgKGk9MTtpPD1uO2krKykgaW5kZWcuaW5zZXJ0KGNudFtpXSk7CiAgICBmb3IgKGk9MTtpPD1uO2krKykgc2NhbmYgKCIlZCIsJmFyYVtpXSk7CgogICAgaWYgKGNoaykgZm9yIChpPTE7aTw9bjtpKyspIHsKICAgICAgICB1PWFyYVtpXTsKICAgICAgICBpdD1pbmRlZy5iZWdpbigpOwogICAgICAgIGlmIChjbnRbdV0hPSppdCkgewogICAgICAgICAgICBjaGs9ZmFsc2U7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpbmRlZy5lcmFzZShpdCk7CiAgICAgICAgdD1lZGdlc1t1XS5zaXplKCk7CiAgICAgICAgZm9yIChqPTA7ajx0O2orKykgewogICAgICAgICAgICB2PWVkZ2VzW3VdW2pdOwogICAgICAgICAgICBpbmRlZy5lcmFzZShjbnRbdl0pOwogICAgICAgICAgICBjbnRbdl0tLTsKICAgICAgICAgICAgaW5kZWcuaW5zZXJ0KGNudFt2XSk7CiAgICAgICAgfQogICAgfQoKICAgIGlmIChjaGspIGNvdXQ8PCJZRVMiOwogICAgZWxzZSBjb3V0PDwiTk8iOwoKICAgIHJldHVybiAwOwp9