#include<iostream>
#include<vector>
using namespace std;

int main()
{
    int n,m;
    vector<int> g[300005];
    cin>>n>>m;
    int a[n];
    int pos[n+1]={0};
    int freq[n+1]={0};
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        pos[a[i]]=i+1;
    }
    for(int i=0;i<m;++i)
    {
        int x,y;cin>>x>>y;
        if(pos[x]<pos[y])
        {
            freq[pos[x]]++;
            g[y].push_back(x);
        }
    }
    int ans=0;
    for(int i=n-1;i>0;--i)
    {
        if(freq[i]==n-i-ans)
        {
            ans++;
            for(int j=0;j<g[a[i]].size();j++)
            {
            freq[pos[g[a[i]][j]]]--;
            }
        }
    }
    cout<<ans;
}