/*input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int alln,allq;
int num[300005];
vector <int> V[300005];
bool flag[300005];
int p[300005];
int main()
{
scanf("%d%d",&alln,&allq);
for(int i=1;i<=alln;++i){
scanf("%d",&num[i]);
}
for(int i=1;i<=allq;++i){
int u,v;
scanf("%d%d",&u,&v);
if(v == num[alln])
flag[u] = true;
V[v].push_back(u);
}
int cnt =0;
int ans = 0;
for(int i=alln-1;i>=1;--i){
if( flag[num[i]] && cnt == p[num[i]] ){
ans ++;
}
else{
cnt++;
for(int j= 0;j<=V[num[i] ].size();++j){
p[ V[num[i]][j] ]++;
}
}
}
printf("%d",ans);
return 0;
}
LyppbnB1dAozIDMKMSAyIDMKNCA1IDYKNyA4IDkKMSA0IDcKMiA1IDYKMyA4IDkKCiovCiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgYWxsbixhbGxxOwppbnQgbnVtWzMwMDAwNV07CnZlY3RvciA8aW50PiBWWzMwMDAwNV07CmJvb2wgZmxhZ1szMDAwMDVdOwppbnQgcFszMDAwMDVdOwoKaW50IG1haW4oKQp7CglzY2FuZigiJWQlZCIsJmFsbG4sJmFsbHEpOwoJZm9yKGludCBpPTE7aTw9YWxsbjsrK2kpewoJCXNjYW5mKCIlZCIsJm51bVtpXSk7Cgl9Cglmb3IoaW50IGk9MTtpPD1hbGxxOysraSl7CgkJaW50IHUsdjsKCQlzY2FuZigiJWQlZCIsJnUsJnYpOwoJCWlmKHYgPT0gbnVtW2FsbG5dKQoJCQlmbGFnW3VdID0gdHJ1ZTsKCQlWW3ZdLnB1c2hfYmFjayh1KTsKCX0KCWludCBjbnQgPTA7CglpbnQgYW5zID0gMDsKCWZvcihpbnQgaT1hbGxuLTE7aT49MTstLWkpewoJCWlmKCBmbGFnW251bVtpXV0gJiYgY250ID09IHBbbnVtW2ldXSApewoJCQlhbnMgKys7CgkJfQoJCWVsc2V7CgkJCWNudCsrOwoJCQlmb3IoaW50IGo9IDA7ajw9VltudW1baV0gXS5zaXplKCk7KytqKXsKCQkJCXBbIFZbbnVtW2ldXVtqXSBdKys7CgkJCX0KCQl9Cgl9CglwcmludGYoIiVkIixhbnMpOwoJcmV0dXJuIDA7Cn0=