#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, d[1011000], j, k, n, m, timer = 0, l, r, x, y, us[500020];
int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
vector<pair<int, pair<int, int> > > v;
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    us[i + 1] = INF;
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &d[i]);
    if (us[d[i]] == INF) us[d[i]] = i + 1;
  }
  for (i = 0; i < n; i++) {
    v.push_back(make_pair(us[i + 1], make_pair(i + 1, c[i])));
  }
  sort(v.begin(), v.end());
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (v[j].second.first == d[i]) break;
      cnt += v[j].second.second;
    }
    for (; j > 0; j--) {
      swap(v[j], v[j - 1]);
    }
  }
  cout << cnt << endl;
  return 0;
}
