George is a cat, so he loves playing very much.

Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the right with integers from 1 to n. Then the i-th card from the left contains number pi (1 ≤ pi ≤ n). 

Vitaly wants the row to have exactly k cards left. He also wants the i-th card from left to have number bi written on it. Vitaly gave a task to George, to get the required sequence of cards using the remove operation n - k times.

In one remove operation George can choose w (1 ≤ w; w is not greater than the current number of cards in the row) contiguous cards (contiguous subsegment of cards). Let's denote the numbers written on these card as x1, x2, ..., xw (from the left to the right). After that, George can remove the card xi, such that xi ≤ xj for each j (1 ≤ j ≤ w). After the described operation George gets w pieces of sausage.

George wondered: what maximum number of pieces of sausage will he get in total if he reaches his goal and acts optimally well? Help George, find an answer to his question!

Input

The first line contains integers n and k (1 ≤ k ≤ n ≤ 106) — the initial and the final number of cards.

The second line contains n distinct space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the initial row of cards. 

The third line contains k space-separated integers b1, b2, ..., bk — the row of cards that you need to get. It is guaranteed that it's possible to obtain the given row by using the remove operation for n - k times.

Output

Print a single integer — the maximum number of pieces of sausage that George can get if he acts optimally well.

Examples

Input

3 2
2 1 3
1 3


Output

1


Input

10 5
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10


Output

30
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
  for (auto& v : t) {
    i >> v;
  }
  return i;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {
  o << p.first << ' ' << p.second;
  return o;
}
template <typename T>
std::ostream& operator<<(std::ostream& o, const vector<T>& t) {
  if (t.empty()) o << '\n';
  for (size_t i = 0; i < t.size(); ++i) {
    o << t[i] << " \n"[i == t.size() - 1];
  }
  return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
bool in(T a, T b, T c) {
  return a <= b && b < c;
}
unsigned int logceil(int first) {
  return 8 * sizeof(int) - __builtin_clz(first);
}
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
  hash<T> t;
  hash<U> u;
  size_t operator()(const pair<T, U>& p) const {
    return t(p.first) ^ (u(p.second) << 7);
  }
};
}  // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      l = m + 1;
      r = m;
    } else {
      h = m - 1;
    }
  }
  return r;
}
template <typename F>
double bshd(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      l = m;
    } else {
      h = m;
    }
  }
  return (l + h) / 2;
}
template <typename T, typename F>
T bsl(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      h = m - 1;
      r = m;
    } else {
      l = m + 1;
    }
  }
  return r;
}
template <typename F>
double bsld(double l, double h, const F& f, double p = 1e-9) {
  unsigned int r = 3 + (unsigned int)log2((h - l) / p);
  while (r--) {
    double m = (l + h) / 2;
    if (f(m)) {
      h = m;
    } else {
      l = m;
    }
  }
  return (l + h) / 2;
}
template <typename T>
T gcd(T a, T b) {
  if (a < b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}
template <typename T>
class vector2 : public vector<vector<T>> {
 public:
  vector2() {}
  vector2(size_t a, size_t b, T t = T())
      : vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T>
class vector3 : public vector<vector2<T>> {
 public:
  vector3() {}
  vector3(size_t a, size_t b, size_t c, T t = T())
      : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T>
class vector4 : public vector<vector3<T>> {
 public:
  vector4() {}
  vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
      : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T>
class vector5 : public vector<vector4<T>> {
 public:
  vector5() {}
  vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
      : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
template <typename F>
struct NoOp {
  void setup(unsigned int, F) {}
  void op(F& p, F n, unsigned int, unsigned int) { p = n; }
  void down(F&, F&, F&, unsigned int, unsigned int) {}
};
template <typename F, typename SetOp, typename PowerOp>
struct Lazy {
  void setup(unsigned int s, F def) {
    this->def = def;
    this->s = s;
    L = new F[s]();
    fill(L, L + s, def);
  }
  void down(F& u, F& l, F& r, unsigned int i, unsigned int s) {
    op(l, L[i], i << 1, s >> 1);
    op(r, L[i], i << 1 | 1, s >> 1);
    L[i] = def;
  }
  void op(F& p, F n, unsigned int i, unsigned int s) {
    p = sop(p, pop(n, s));
    if (i < this->s) this->L[i] = sop(this->L[i], n);
  }
  SetOp sop;
  PowerOp pop;
  F* L;
  unsigned int s;
  F def;
};
template <typename F, typename CombineOp, typename ModifyOp = NoOp<F>>
struct SegTree {
  void setup(unsigned int s, F def) {
    n = 1 << logceil(s);
    T = vector<F>(2 * n, def);
    for (unsigned int i = n - 1; i > 0; i--)
      T[i] = cop(T[i << 1], T[i << 1 | 1]);
    mop.setup(2 * n, def);
  }
  void setup(vector<F>& data, F def = F()) {
    n = 1 << logceil(data.size());
    T = vector<F>(2 * n, def);
    copy(data.begin(), data.end(), T.begin() + n);
    for (unsigned int i = n - 1; i > 0; i--)
      T[i] = cop(T[i << 1], T[i << 1 | 1]);
    mop.setup(2 * n, def);
  }
  inline void put(unsigned int first, F n) { put(first, first, n); }
  inline void put(unsigned int from, unsigned int to, F v) {
    put2(from, to + 1, v, 1, n);
  }
  inline F get(unsigned int first) { return get(first, first); }
  inline F get(unsigned int from, unsigned int to) {
    return get2(from, to + 1, 1, n);
  }
  void put2(unsigned int from, unsigned int to, F v, unsigned int i,
            unsigned int s) {
    if (from == 0 && to == s) {
      mop.op(T[i], v, i, s);
      return;
    }
    mop.down(T[i], T[i << 1], T[i << 1 | 1], i, s);
    s >>= 1;
    i <<= 1;
    if (to <= s) {
      put2(from, to, v, i, s);
    } else if (from >= s) {
      put2(from - s, to - s, v, i | 1, s);
    } else {
      put2(from, s, v, i, s);
      put2(0, to - s, v, i | 1, s);
    }
    T[i >> 1] = cop(T[i], T[i | 1]);
  }
  F get2(unsigned int from, unsigned int to, unsigned int i, unsigned int s) {
    while (true) {
      if (from == 0 && to == s) return T[i];
      mop.down(T[i], T[i << 1], T[i << 1 | 1], i, s);
      s >>= 1;
      i <<= 1;
      if (to > s) {
        to -= s;
        if (from >= s) {
          from -= s;
          i |= 1;
        } else
          return cop(get2(from, s, i, s), get2(0, to, i | 1, s));
      }
    }
  }
  unsigned int n;
  vector<F> T;
  CombineOp cop;
  ModifyOp mop;
};
template <typename F>
struct AddOp {
  F operator()(F a, F b) { return a + b; }
};
template <typename F>
struct MinOp {
  F operator()(F a, F b) { return std::min(a, b); }
};
template <typename F>
struct MaxOp {
  F operator()(F a, F b) { return std::max(a, b); }
};
template <typename F>
struct MultiplyOp {
  F operator()(F a, F b) { return a * b; }
};
template <typename F>
struct MultOp {
  F operator()(F a, unsigned int b) { return a * b; }
};
template <typename F>
struct IdempOp {
  F operator()(F a, unsigned int b) { return a; }
};
template <typename F>
struct InverseOp {
  F operator()(F a, F b) { return b ? b - a : a; }
};
template <typename T>
using AddSumTree = SegTree<T, AddOp<T>, Lazy<T, AddOp<T>, MultOp<T>>>;
template <typename T>
using AddMaxTree = SegTree<T, MaxOp<T>, Lazy<T, AddOp<T>, IdempOp<T>>>;
template <typename T>
using AddMinTree = SegTree<T, MinOp<T>, Lazy<T, AddOp<T>, IdempOp<T>>>;
template <typename T>
using AssignMinTree = SegTree<T, MinOp<T>, Lazy<T, MinOp<T>, IdempOp<T>>>;
template <typename T>
using AssignMaxTree = SegTree<T, MaxOp<T>, Lazy<T, MaxOp<T>, IdempOp<T>>>;
template <typename T>
using XorTree = SegTree<T, AddOp<T>, Lazy<T, InverseOp<T>, MultOp<T>>>;
template <typename T>
using SetMinTree = SegTree<T, MinOp<T>>;
template <typename T>
using SetMaxTree = SegTree<T, MaxOp<T>>;
template <typename T>
using SetMulTree = SegTree<T, MultiplyOp<T>>;
template <typename T>
struct Fenwick {
  explicit Fenwick(unsigned int N = 0, T t = T())
      : N(1u << logceil(N)), F(this->N, t), t(t) {}
  explicit Fenwick(const vector<T>& A, T t = T())
      : N(1u << logceil(A.size())), F(A), t(t) {
    F.resize(N);
    fill(F.begin() + A.size(), F.end(), t);
    for (int i = 0; i < N; i++) {
      int j = i + lsb(i + 1);
      if (j < N) F[j] += F[i];
    }
  }
  void add(int i, T v) {
    while (i <= N) {
      F[i] += v;
      i += lsb(i + 1);
    }
  }
  T sum(int i) const {
    T sum(t);
    while (i) {
      sum += F[i - 1];
      i -= lsb(i);
    }
    return sum;
  }
  T range(int i, int j) const {
    j++;
    T s(t);
    while (j > i) {
      s += F[j - 1];
      j -= lsb(j);
    }
    while (i > j) {
      s -= F[i - 1];
      i -= lsb(i);
    }
    return s;
  }
  T get(int i) const { return range(i, i); }
  void set(int i, T v) { add(i, v - get(i)); }
  constexpr int lsb(int i) const { return i & -i; }
  unsigned int N;
  vector<T> F;
  T t;
};
template <typename T>
struct Fenwick2 {
  explicit Fenwick2(unsigned int N = 0, T t = T())
      : N(1u << logceil(N)), F(this->N, this->N, t), t(t) {}
  void add(int first, int second, T v) {
    while (first <= N) {
      int z = second;
      while (z <= N) {
        F[first][z] += v;
        z += lsb(z + 1);
      }
      first += lsb(first + 1);
    }
  }
  T sum(int first, int second) {
    T sum(t);
    while (first <= N) {
      int z = second;
      while (z <= N) {
        sum += F[first][z];
        z -= lsb(z + 1);
      }
      first -= lsb(first + 1);
    }
    return sum;
  }
  T range(int x1, int y1, int x2, int y2) {
    T ans = sum(x2, y2);
    if (x1) ans -= sum(x1 - 1, y2);
    if (y1) ans -= sum(x2, y1 - 1);
    if (x1 && y1) ans += sum(x1 - 1, y1 - 1);
    return ans;
  }
  constexpr int lsb(int i) const { return i & -i; }
  unsigned int N;
  vector2<T> F;
  T t;
};
class TaskE {
 public:
  void solve(istream& cin, ostream& cout) {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    cin >> P;
    for (int& p : P) --p;
    vector<int> B(K);
    cin >> B;
    for (int& b : B) --b;
    vector<bool> U(N, false);
    for (int b : B) U[b] = true;
    vector<int> L(N, -1), H(N, -1), I(N, -1);
    SetMaxTree<int> T;
    T.setup(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      if (U[P[i]]) {
        T.put(P[i] + 1, i + 1);
      } else {
        I[P[i]] = i;
        L[P[i]] = T.get(0, P[i]);
      }
    }
    SetMinTree<int> TT;
    TT.setup(N + 1, N);
    for (int i = N - 1; i >= 0; --i) {
      if (U[P[i]]) {
        TT.put(P[i] + 1, i);
      } else {
        H[P[i]] = TT.get(0, P[i]);
      }
    }
    Fenwick<int> F(N, 0);
    for (int i = 0; i < N; ++i) F.add(i, 1);
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
      if (!U[i]) {
        ans += F.range(L[i], H[i] - 1);
        F.add(I[i], -1);
      }
    }
    cout << ans << endl;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  TaskE solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
