#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9+7;
const int inf = 1e18;
using namespace std;

main()
{
    fastread;
    int n, m; cin>>n>>m; int a[n+1]; f(i, 1, n+1) cin>>a[i];
    vector<int> v[n+1];
    f(i, 1, m+1)
    {
        int s, d; cin>>s>>d; v[s].pb(d); 
    }
    int pos[n+1];  f(i, 1, n+1) pos[a[i]] = i;
    int ans = 0;
    bool ok[n+1]; memset(ok, 0, sizeof(ok));
//    f(i, 1, n+1) cout<<pos[i]<<" "; cout<<"\n";
    for(int i = n-1; i > 0; i--)
    {
        int t = 0;
        for(int j : v[a[i]])
        {
            if(pos[j] < i || ok[j]) continue;
            t++;
        }
//        cout<<i<<" "<<t<<"\n";
        if(t == n - i - ans)
        {
            ok[i] = 1; ans++;
        }
    }
    cout<<ans;
}