#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int H[300005];
struct node {
  int x, y;
  node(int a = 0, int b = 0) : x(a), y(b) {}
  void input() {
    scanf("%d%d", &x, &y);
    x = H[x];
    y = H[y];
    if (x > y) swap(x, y);
  }
  bool operator<(const node& tt) const {
    if (y == tt.y) return x < tt.x;
    return y < tt.y;
  }
} q[300005];
int n, m;
long long add(int a, int b) { return (long long)(b - a + 1) * (a + b) >> 1; }
void solve() {
  int i, j = 1, last = 1;
  for (i = 1; i <= m; ++i) {
    ans += add(last - j + 1, q[i].y - j);
    last = q[i].y;
    j = max(j, q[i].x + 1);
  }
  ans += add(last - j + 1, n - j + 1);
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &j);
    H[j] = i;
  }
  for (i = 1; i <= m; ++i) q[i].input();
  sort(q + 1, q + 1 + m);
  solve();
  printf("%I64d\n", ans);
  return 0;
}
