#include <bits/stdc++.h>

//#define MULTI_TEST "HyNnl"
#define fi first
#define se second
#define whatIs(a) cout << #a " is " << (a) << endl;

using namespace std;

typedef pair<long long, long long> pt;

const int N = 300005;
const long long base = 1e9+7;
const long long inf = 1e18+7;
clock_t t1,t2;
long long n, m, k, Min;
set <int> c[N];
int a[N];

void process(int i) {
    if (i <= Min) return;
    while (1) {
        //cout <<c[a[i]].count(a[i-1]) << endl;
        if (c[a[i]].count(a[i-1]) > 0) {
            //cout << "FUCK" << endl;
            swap(a[i], a[i-1]);
            i--;
            if (i == 0) break;
        }
        else {
            Min++;
            int v = a[i-1];
            process(i-1);
            if (a[i-1] == v) break;
        }
    }
}

void Input () {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    while (m--) {
        int u, v;
        cin >> u >> v;
        c[v].insert(u); 
    }
}

void Solve () {
    Min = 0;
    int k = a[n - 1];
    process(n - 1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == k) ans = i;
    }
//     for (int i = 0; i < n; i++) {
//         cout << a[i] << " \n"[i==n-1?1:0];
//     }
    cout << (n - ans - 1) << endl;
}

main () {
    cerr << "Program is running" << endl;
    t1 = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef MULTI_TEST
    int t; cin >> t;
    while (t--) {
        Input();
        Solve();
    }
    #else
    Input();
    Solve();
    #endif
    t2 = clock();
    float diff ((float)t2-(float)t1);
    float seconds = diff / CLOCKS_PER_SEC;
    cerr << "\nRunning in " << seconds << " seconds" << endl;
}
