#include <bits/stdc++.h>
using namespace std;
struct st {
  signed long long int ans = -1000000007;
  signed long long int pre = -1000000007;
  signed long long int suf = -1000000007;
  signed long long int sum = -1000000007;
} tree[1000000 * 4 + 5];
void update(int i, int si, int sj, int q, signed long long int b) {
  if (si == sj) {
    tree[i].sum = tree[i].ans = tree[i].pre = tree[i].suf = b;
  } else {
    int mid = (si + sj) / 2;
    if (q <= mid)
      update(2 * i, si, mid, q, b);
    else
      update(2 * i + 1, mid + 1, sj, q, b);
    tree[i].sum = (tree[2 * i].sum + tree[2 * i + 1].sum);
    tree[i].ans = max(tree[2 * i].ans, tree[2 * i + 1].ans);
    tree[i].ans = max(tree[i].ans, tree[2 * i].suf + tree[2 * i + 1].pre);
    tree[i].pre = max(tree[2 * i].pre, tree[2 * i].sum + tree[2 * i + 1].pre);
    tree[i].suf =
        max(tree[2 * i + 1].suf, tree[2 * i + 1].sum + tree[2 * i].suf);
  }
}
int A[1000000 + 5];
int B[1000000 + 5];
int main() {
  int K, N, x;
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &x);
    A[x] = i;
    update(1, 1, N, i, 1);
  }
  for (int i = 1; i <= K; ++i) {
    scanf("%d", &x);
    B[x] = 1;
  }
  signed long long int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (B[i] == 0) {
      update(1, 1, N, A[i], 1000000LL * 1000000007);
      ans += tree[1].ans - 1000000LL * 1000000007 + 1;
      update(1, 1, N, A[i], 0);
    } else {
      update(1, 1, N, A[i], -1000000007);
    }
  }
  cout << ans;
}
