#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, m;
int arr[300005];
int mark[300005];
int l[300005];
vector<vector<int> > graph(300005);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    mark[arr[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  l[1] = 1;
  int maxi = 1;
  long long ret = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < graph[arr[i]].size(); j++) {
      if (mark[graph[arr[i]][j]] < i)
        maxi = max(maxi, mark[graph[arr[i]][j]] + 1);
    }
    ret += (i - maxi + 1);
  }
  cout << ret;
}
