#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
int n, m;
bool vis[1000100];
class segTree {
 private:
  struct segment {
    int l, r, sum, min;
  } seg[1000100 << 2];

 public:
  void pushup(int rt) {
    seg[rt].min = min(seg[(rt << 1)].min, seg[(rt << 1 | 1)].min);
    seg[rt].sum = seg[(rt << 1)].sum + seg[(rt << 1 | 1)].sum;
  }
  void build(int l, int r, int rt) {
    seg[rt].l = l, seg[rt].r = r;
    if (l == r) {
      scanf("%d", &seg[rt].min);
      seg[rt].sum = 1;
      return;
    }
    int mid = (seg[rt].l + seg[rt].r) >> 1;
    build(l, mid, (rt << 1));
    build(mid + 1, r, (rt << 1 | 1));
    pushup(rt);
  }
  int remove(int val, int L, int R, int rt) {
    if (seg[rt].l == seg[rt].r) {
      if (seg[rt].min != val) return 0;
      seg[rt].min = INF;
      seg[rt].sum = 0;
      return seg[rt].l;
    }
    int pos = 0;
    if (L <= seg[rt].l && seg[rt].r <= R) {
      if (seg[(rt << 1)].min == val)
        pos = remove(val, L, R, (rt << 1));
      else if (seg[(rt << 1 | 1)].min == val)
        pos = remove(val, L, R, (rt << 1 | 1));
    } else {
      int mid = (seg[rt].l + seg[rt].r) >> 1;
      if (L <= mid) pos += remove(val, L, R, (rt << 1));
      if (mid < R) pos += remove(val, L, R, (rt << 1 | 1));
    }
    pushup(rt);
    return pos;
  }
  int getSum(int L, int R, int rt) {
    if (L <= seg[rt].l && seg[rt].r <= R) return seg[rt].sum;
    int mid = (seg[rt].l + seg[rt].r) >> 1, sum = 0;
    if (L <= mid) sum += getSum(L, R, (rt << 1));
    if (mid < R) sum += getSum(L, R, (rt << 1 | 1));
    return sum;
  }
  int getMin(int L, int R, int rt) {
    if (L <= seg[rt].l && seg[rt].r <= R) return seg[rt].min;
    int mid = (seg[rt].l + seg[rt].r) >> 1, Min = INF;
    if (L <= mid) Min = min(Min, getMin(L, R, (rt << 1)));
    if (mid < R) Min = min(Min, getMin(L, R, (rt << 1 | 1)));
    return Min;
  }
} T;
long long solve(int l, int r) {
  if (r < l) return 0;
  long long ans = 0;
  int val, len = T.getSum(l, r, 1);
  if (len == 0) return 0;
  while (len && !vis[(val = T.getMin(l, r, 1))]) {
    ans += len--;
    T.remove(val, l, r, 1);
  }
  int pos = T.remove(val, l, r, 1);
  return ans + solve(l, pos - 1) + solve(pos + 1, r);
}
int main() {
  scanf("%d%d", &n, &m);
  T.build(1, n, 1);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    vis[x] = true;
  }
  printf("%I64d\n", solve(1, n));
  return 0;
}
