#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 4e5 + 100;
int n, m;
vector<int> vc[N];
int to[N];
multiset<int> st;
void Ac() {
  for (int i = 1, v; i <= n; ++i) {
    scanf("%d", &v);
    to[v] = i;
  }
  st.insert(n + 1);
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    u = to[u];
    v = to[v];
    if (u > v) swap(u, v);
    vc[u].push_back(v);
    st.insert(v);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += (*st.begin()) - i;
    for (int v : vc[i]) {
      st.erase(st.lower_bound(v));
    }
  }
  printf("%I64d\n", ans);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    Ac();
  }
  return 0;
}
