#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, mod = 1e9 + 7;
int n, m, a[N], tree[2 * N], pos[N];
std::vector<int> g[N];
void build() {
  for (int i = n - 1; i > 0; --i)
    tree[i] = max(tree[i << 1], tree[(i << 1) ^ 1]);
}
int query(int l, int r) {
  int ans = 0;
  for (l += n - 1, r += n - 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max(ans, tree[l++]);
    if (r & 1) ans = max(ans, tree[--r]);
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  while (m--) {
    int u, v;
    scanf("%d %d", &u, &v);
    u = pos[u];
    v = pos[v];
    if (u < v) swap(u, v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i) {
    sort(g[i].begin(), g[i].end());
    if (!g[i].empty()) tree[n + i - 1] = g[i].back();
  }
  build();
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int l = 0, r = i + 1;
    while (r - l > 1) {
      int mid = (r + l) >> 1;
      bool ok = (query(mid, i + 1) < mid);
      if (ok)
        r = mid;
      else
        l = mid;
    }
    ans += (i - r + 1);
  }
  printf("%I64d\n", ans);
}
