#include <bits/stdc++.h>
using namespace std;
int aage(auto m,int a[],int c[],int i)
{
    int j=i-1;
    if(i<=1 || c[i]==0) return i;
    if(m[{a[i],a[j]}])
    {
        int t=a[i];a[i]=a[j];a[j]=t;
        c[a[j]]--;
        t=aage(m,a,c,i-1);
        //cout<<"aaya "<<i<<" ga1ya "<<t<<endl;
        return t;
    }
    else
    {
        int b=1;
        while(i-1>b && !m[{a[i],a[i-1]}])
        {
            b=aage(m,a,c,i-1);
            //cout<<b<<" b "<<a[i]<<endl;
        }
        if(m[{a[i],a[i-1]}])
            b=aage(m,a,c,i-1);
        //cout<<"aaya "<<i<<" gaya "<<b<<endl;
        return b;
    }
}
int main()
{
    int n,ma;
    cin>>n>>ma;
    int a[n+1]={0};
    for(int i=0;i<n;i++) cin>>a[i+1];
    map< pair<int,int> ,int> m;
    int c[n+1]={0};
    for(int i=0;i<ma;i++)
    {
        int u,r;cin>>u>>r;
        m[{r,u}]++;
        c[r]++;
    }
    int i=aage(m,a,c,n);
    cout<<n-i<<endl;
    return 0;
}
