#include <bits/stdc++.h>
using namespace std;
int pos[400000];
int maxi[400000];
long long int func(int n) {
  int beg = 1;
  long long int ans = 0;
  long long int l = 0;
  for (int i = 2; i <= n; i++) {
    int temp = maxi[i];
    if (temp >= beg && temp <= i - 1) {
      l = temp - beg + 1;
      ans += l * (l + 1) / 2;
      ans += l * (long long)(i - 1 - temp);
      beg = temp + 1;
    }
  }
  l = n - beg + 1;
  ans += l * (l + 1) / 2;
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (pos[u] > pos[v]) swap(u, v);
    maxi[pos[v]] = max(maxi[pos[v]], pos[u]);
  }
  cout << func(n) << endl;
  return 0;
}
