#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ar[n + 1];
  int loc[n + 1];
  for (int i = 1; i <= n; i++) cin >> ar[i], loc[ar[i]] = i;
  int helper[n + 1];
  fill(helper, helper + n + 1, 0);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int pos1 = loc[x], pos2 = loc[y];
    if (pos1 > pos2) {
      helper[x] = max(helper[x], pos2);
    } else {
      helper[y] = max(helper[y], pos1);
    }
  }
  int curr = 1;
  long long ans = 1;
  for (int i = 2; i <= n; i++) {
    int currpos = helper[ar[i]] + 1;
    curr = max(currpos, curr);
    ans += i - curr + 1;
  }
  cout << ans;
  return 0;
}
