#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
int otr[N];
int poz[N];
int bad[N];
long long ans;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    poz[x] = i;
    otr[i] = n;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = poz[x];
    y = poz[y];
    if (x > y) swap(x, y);
    otr[x] = min(otr[x], y);
  }
  int r = 0;
  for (int l = 0; l < n; l++) {
    while (r < n && bad[r] == 0) {
      bad[otr[r]]++;
      r++;
    }
    ans += r - l;
    bad[otr[l]]--;
  }
  cout << ans;
  return 0;
}
