#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17 + 10;
const int N = 1e6 + 10;
const long long mod = 998244353;
const int base = 131;
map<string, int> ml;
long long b[N], vis[N], c[N], num[N], a[N], t, n, m, x, y, k;
long long ex, ey, cnt, ans, sum, flag;
int dp[N][3][3];
vector<int> v[N];
map<int, int> mp;
set<int> second;
stack<int> st;
long long pos[N], f[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    pos[x] = i;
    f[i] = n;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    long long l = min(pos[x], pos[y]);
    long long r = max(pos[x], pos[y]);
    f[l] = min(f[l], r - 1);
  }
  for (int i = n - 1; i; i--) f[i] = min(f[i], f[i + 1]);
  for (int i = 1; i <= n; i++) {
    ans += f[i] - i + 1;
  }
  cout << ans << endl;
}
