#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int lg = 20;
int tb[N][lg];
int nxt[N], n, m;
int a[N], x, y;
int pos[N];
int sv[N];
int qry(int l, int r) {
  int k = sv[r - l + 1];
  return min(tb[l][k], tb[r - (1 << k) + 1][k]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; (1 << i) < N; i++) sv[1 << i] = i;
  for (int i = 1; i < N; i++)
    if (!sv[i]) sv[i] = sv[i - 1];
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  fill(nxt, nxt + n + 1, n + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    x = pos[x];
    y = pos[y];
    if (y > x) nxt[x] = min(nxt[x], y);
    if (x > y) nxt[y] = min(nxt[y], x);
  }
  for (int i = 1; i <= n; i++) {
    tb[i][0] = nxt[i];
  }
  for (int j = 1; j < lg; j++)
    for (int i = 1; i + (1 << (j - 1)) <= n; i++)
      tb[i][j] = min(tb[i][j - 1], tb[i + (1 << (j - 1))][j - 1]);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int lo = i, hi = n;
    while (lo < hi) {
      int md = lo + (hi - lo + 1) / 2;
      if (qry(i, md) > md)
        lo = md;
      else
        hi = md - 1;
    }
    ans += (lo - i + 1);
  }
  cout << ans << '\n';
  return 0;
}
