#include <bits/stdc++.h>
const int N = 3e5 + 7;
using namespace std;
int p[N];
vector<int> stk[N];
multiset<int> S;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    p[x] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = p[x], y = p[y];
    if (x > y) swap(x, y);
    stk[x].push_back(y);
    S.insert(y);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!S.empty())
      ans += *S.begin() - i;
    else
      ans += n - i + 1;
    for (int j = 0; j < stk[i].size(); j++) S.erase(S.find(stk[i][j]));
  }
  printf("%lld\n", ans);
  return 0;
}
