#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    long long n;
    cin >> n;
  }
} __S;
vector<long long> g[311111];
long long p[311111];
long long cnt[311111];
bool in(long long x, set<long long> &s) { return s.find(x) != s.end(); }
void add(long long i, set<long long> &s) {
  for (long long jj = 0; jj < (long long)(g[i].size()); jj++) {
    long long j = g[i][jj];
    cnt[j]++;
    if (cnt[j] == 1) s.insert(j);
  }
}
void sub(long long i, set<long long> &s) {
  for (long long jj = 0; jj < (long long)(g[i].size()); jj++) {
    long long j = g[i][jj];
    cnt[j]--;
    if (cnt[j] == 0) s.erase(j);
  }
}
int main(void) {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> p[i];
  }
  for (long long i = 0; i < (long long)(m); i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long ans = 0;
  long long r = 0;
  set<long long> s;
  for (long long l = 0; l < n; l++) {
    while (r < n && !in(p[r], s)) {
      add(p[r], s);
      r++;
    }
    ans += r - l;
    sub(p[l], s);
  }
  cout << ans << '\n';
  return 0;
}
