#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int arr[MAXN];
int stop[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  memset(stop, -1, sizeof(stop));
  for (int i = (0); i < (n); i++) {
    int x;
    cin >> x;
    arr[x] = i;
  }
  for (int i = (0); i < (m); i++) {
    int x, y;
    cin >> x >> y;
    int l = arr[x], r = arr[y];
    if (l > r) swap(l, r);
    stop[r] = max(stop[r], l);
  }
  long long sol = 0;
  long long cookie = 0;
  int last = 0;
  for (int i = (0); i < (n); i++) {
    if (stop[i] != -1) {
      last = max(stop[i], last);
      cookie = i - last - 1;
    }
    cookie++;
    sol += cookie;
  }
  cout << sol;
  return 0;
}
