#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX(a, b) a = max(a, b)
const int MAXN = 250001;
const int MAXK = 250001;
int n, k, m;
vector<int> g[MAXK], gr[MAXK], gc[MAXK];
// bitset<MAXK> bs[MAXK];
set<pair<int, int>> edges;
int t[MAXN], scc[MAXK], cnt[MAXK], timer = 0;
bool vis[MAXK];
stack<int> order;
bool seen4[MAXK];
void dfs(int u) {
vis[u] = 1;
for (int v : g[u]) {
if (!vis[v]) dfs(v);
}
order.push(u);
}
void dfs2(int u) {
scc[u] = timer;
for (int v : gr[u]) {
if (!scc[v]) dfs2(v);
}
}
// void dfs3(int u) {
// bs[u][u] = 1;
// for (int v : gc[u]) {
// if (bs[v].none()) {
// dfs3(v);
// }
// bs[u] |= bs[v];
// }
// }
bool dfs4(int x, int keres){
if(x == keres)return true;
if(seen4[x]) return false;
seen4[x] = true;
for(int i : gc[x]){
if(dfs4(i, keres)){
return true;
}
}
return false;
}
// bool Q(int u, int v) {
// return bs[scc[u]][scc[v]];
// }
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> t[i];
cin >> m;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
edges.insert({a, b});
g[a].emplace_back(b);
gr[b].emplace_back(a);
}
for (int i = 1; i <= k; i++) {
if (!vis[i]) dfs(i);
}
while (!order.empty()) {
int u = order.top();
order.pop();
if (scc[u]) continue;
timer++;
dfs2(u);
}
for(int i = 1; i <= k; i++) {
for (int v : g[i]) {
if (scc[i] != scc[v]) {
gc[scc[i]].emplace_back(scc[v]);
}
}
}
for (int i = 1; i <= timer; i++) {
sort(gc[i].begin(), gc[i].end());
gc[i].erase(unique(gc[i].begin(), gc[i].end()), gc[i].end());
}
int last = n+1;
for (int i = 1; i <= n; i++) {
if(i == 1 || scc[t[i]] != scc[t[i-1]]) cnt[scc[t[i]]]++;
if (cnt[scc[t[i]]] == 2){
last = i-1;
break;
}
}
// int last = 0;
// for (int i = 1; i <= timer; i++) {
// if (first[i] != 1e6) last = max(last, first[i]);
// }
// for (last++; last <= n; last++) {
// if (scc[t[last]] != scc[t[last-1]]) {
// last--;
// break;
// }
// }
// for (int i = 1; i <= timer; i++) {
// if (bs[i].none()) dfs3(i);
// }
last = min(last, n);
int utolsojo = last;
for(int i = last-1; i >= 1; i--){
if(i < n && scc[t[i]] == scc[t[i+1]]) continue;
if (i == n) {
// dfs4(i, -1);
continue;
}
seen4[scc[t[i]]] = 0;
if(!dfs4(scc[t[i]], scc[t[i+1]])){
utolsojo = i;
}
}
utolsojo = min(utolsojo, n);
int ans = 2;
for(int i = 2; i <= utolsojo; i++){
if(edges.count({t[i-1], t[i]}) || t[i-1] == t[i]){
ans+=2;
} else {
ans++;
}
}
cout<<ans<<endl;
return 0;
}