#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, p[312345];
set<int> enemies[312345];
multiset<int> shall_not_pass;
void insert_set_to_ms(multiset<int>& ms, set<int>& s) {
  for (auto val : s) ms.insert(val);
}
void remove_set_from_ms(multiset<int>& ms, set<int>& s) {
  for (auto val : s) ms.erase(ms.find(val));
}
void print_ms(multiset<int> ms) {
  for (auto val : ms) printf("%d ", val);
  puts("");
}
void print_set(set<int> s) {
  for (auto val : s) printf("%d ", val);
  puts("");
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &p[i]);
  while (m--) {
    scanf("%d %d", &x, &y);
    enemies[x].insert(y);
    enemies[y].insert(x);
  }
  int i = 0;
  insert_set_to_ms(shall_not_pass, enemies[p[i]]);
  long long ans = 1;
  for (int j = 1; j < n; ++j) {
    while (shall_not_pass.find(p[j]) != shall_not_pass.end()) {
      remove_set_from_ms(shall_not_pass, enemies[p[i]]);
      ++i;
    }
    ans += j - i + 1;
    insert_set_to_ms(shall_not_pass, enemies[p[j]]);
  }
  printf("%lld\n", ans);
  return 0;
}
