#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int rem[1000005];
int lol[1000005];
int pos[1000005];
int nx[1000005][20];
int bit[1000005];
int n, m;
void build() {
  memset(bit, 0, sizeof(bit));
  for (int(a) = (1); (a) <= (n); (a)++) {
    pos[lol[a]] = a;
    nx[a][0] = lol[a];
    if (rem[lol[a]]) nx[a][0] = INF;
  }
  for (int(k) = (1); (k) <= (19); (k)++) {
    for (int(a) = (1); (a) <= (n - (1 << k) + 1); (a)++) {
      nx[a][k] = min(nx[a][k - 1], nx[a + (1 << (k - 1))][k - 1]);
    }
  }
}
int query(int pos, int lim) {
  int ret = 0;
  for (int(a) = (19); (a) >= (0); (a)--) {
    if (pos + (1 << a) - 1 <= n && nx[pos][a] > lim) {
      pos += (1 << a);
      ret += (1 << a);
    }
  }
  return ret;
}
void update(int bit[], int x, int v) {
  for (int i = x; i <= n; i += (i & -i)) {
    bit[i] += v;
  }
}
int query(int bit[], int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= (i & -i)) {
    res += bit[i];
  }
  return res;
}
int query(int bit[], int l, int r) { return query(bit, r) - query(bit, l - 1); }
long long calc() {
  build();
  long long ans = 0;
  for (int(v) = (1); (v) <= (n); (v)++) {
    int a = pos[v];
    if (rem[v] == 1) {
      int tmp = query(a + 1, lol[a]);
      ans += tmp;
      ans -= query(bit, a + 1, a + tmp);
      update(bit, a, 1);
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(a) = (1); (a) <= (n); (a)++) {
    scanf("%d", &lol[a]);
    rem[a] = 1;
  }
  for (int(a) = (1); (a) <= (m); (a)++) {
    int k;
    scanf("%d", &k);
    rem[k] = 0;
  }
  long long ans = n - m;
  ans += calc();
  reverse(lol + 1, lol + n + 1);
  ans += calc();
  printf("%I64d\n", ans);
}
