#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
const long long modo = 1e9 + 7;
const long long inf = 1e16;
const long long ms = (3e5) + 5;
vector<int> vv[ms];
int ar[ms];
int hs[ms];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  int x, y;
  while (m--) {
    cin >> x >> y;
    vv[x].emplace_back(y);
    vv[y].emplace_back(x);
  }
  int st = 1;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    for (int ii : vv[ar[i]]) st = max(st, hs[ii] + 1);
    ans += (i + 1 - st);
    hs[ar[i]] = i;
  }
  cout << ans;
  return 0;
}
