#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define int long long
using namespace std;
int a[300002],b[300002];
vector<int>g[300002];
main(){
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        b[a[i]] = i;
    }
    for (int i =0;i < m; i++){
        int x,y;
        cin >> x >> y;
        g[x].pb(y);
    }
    int ans = 0;
    for (int i = n-2; i >= 0; i--){
        int k = 0;
        for (auto j : g[a[i]]){
            if (b[j] > i)k++;
        }
        if (k == n-1 - i)ans++;
    }
    cout << ans;
    return 0;
}

