#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
vector<int> v[N];
map<pair<int, int>, bool> mp;
int idx[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long res = 0;
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (!mp[{x, y}] && !mp[{y, x}]) v[x].push_back(y), v[y].push_back(x);
  }
  int d = n;
  for (int i = n - 1; i >= 0; i--) {
    int mn = n;
    for (int j = 0; j < v[a[i]].size(); j++) {
      if (idx[v[a[i]][j]]) mn = min(mn, idx[v[a[i]][j]]);
    }
    idx[a[i]] = i;
    d = min(mn, d);
    res += (min(d, mn) - i);
  }
  cout << res;
}
