#include<bits/stdc++.h>
#define ll long int
using namespace std;
ll answer(vector< vector<ll> > &vect,ll pos,ll a[],ll point[])
{   
    if(point[a[pos]]==0)
        point[a[pos]]=1;
    else
        return 0;
    
    
    point[a[pos]]=1;


    ll i,ans=0;
    for(i=0;i<vect[pos].size();i++)
        ans+=answer(vect,vect[pos][i],a,point);
        
    
    
    if(vect[pos].size()==0)
        ans=-1;

    return ans+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q,ans=0;
    cin>>n>>q;
    ll a[n],i,a1,b1,pos[n+1],point[n]={0};// pos array for storing position of a no // point is used for repitition
    vector< vector<ll> >vect1(n+1),vect2(n+1);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        pos[a[i]]=i;
    }

    for(i=0;i<q;i++)
    {
        cin>>a1>>b1;
        vect1[a1].push_back(b1);
        if(pos[a1]<pos[b1])
        vect2[b1].push_back(a1);
    }
    
    ans=answer(vect2,a[n-1],pos,point);
    
    cout<<ans;


}