#include <bits/stdc++.h>
using namespace std;
int p[300010];
int r[300010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    p[x] = i;
  }
  memset(r, 0x3f3f3f3f, sizeof(r));
  int y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    if (p[x] > p[y]) swap(x, y);
    r[p[x]] = min(r[p[x]], p[y]);
  }
  x = n + 1;
  long long ans = 0;
  for (int i = n; i > 0; i--) {
    if (r[i] != 0x3f3f3f3f) x = min(x, r[i]);
    ans += x - i;
  }
  cout << ans;
  return 0;
}
