#include <bits/stdc++.h>
using namespace std;
long long comp(long long c) {
  long long ans = c;
  if (ans % 2 == 0) {
    ans /= 2;
    ans *= (c + 1);
  } else {
    ans *= ((c + 1) / 2);
  }
  return ans;
}
long long worker() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> pid(n + 1);
  int i;
  for (i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    pid[x] = i;
  }
  set<pair<int, int> > foes;
  for (i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int l = min(pid[a], pid[b]);
    int r = max(pid[a], pid[b]);
    foes.insert(make_pair(r, l));
  }
  long long ans = 0;
  set<pair<int, int> >::iterator it;
  int last = 0;
  for (it = foes.begin(); it != foes.end(); it++) {
    int r = it->first;
    int l = it->second;
    long long c1 = r - last;
    long long c2 = r - l - 1;
    if (c2 >= c1) continue;
    ans += (comp(c1) - comp(c2));
    last = l + 1;
  }
  long long d = n - last;
  ans += comp(d);
  return ans;
}
int main() {
  printf("%I64d", worker());
  int xx;
  cin >> xx;
  return 0;
}
