#include <bits/stdc++.h>
using namespace std;
vector<int> Adj[300001];
vector<int> A(300000 + 1);
set<pair<int, int> > Cur;
set<int> Cur_Set;
void add(int i) {
  Cur_Set.insert(A[i]);
  for (auto v : Adj[A[i]]) {
    if (!Cur_Set.count(v)) continue;
    if (A[i] > v)
      Cur.insert(pair<int, int>(v, A[i]));
    else
      Cur.insert(pair<int, int>(A[i], v));
  }
}
void rem(int i) {
  Cur_Set.erase(A[i]);
  for (auto v : Adj[A[i]]) {
    if (!Cur_Set.count(v)) continue;
    if (A[i] > v)
      Cur.erase(pair<int, int>(v, A[i]));
    else
      Cur.erase(pair<int, int>(A[i], v));
  }
}
set<pair<int, int> > Chutiyap;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M, i, L, R;
  cin >> N >> M;
  for (i = 1; i <= N; ++i) cin >> A[i];
  for (i = 0; i < M; ++i) {
    cin >> L >> R;
    if (L > R) swap(L, R);
    Adj[L].push_back(R);
    Adj[R].push_back(L);
  }
  long long ans = 0;
  L = 1;
  for (i = 1; i <= N; ++i) {
    add(i);
    while (Cur.size() && L <= i) {
      rem(L);
      ++L;
    }
    ans += i - L + 1;
  }
  cout << ans;
  return 0;
}
