#include <bits/stdc++.h>
using namespace std;
long long n, q, a[1005], w[505], h, k, ans, t;
bitset<505> b;
map<long long, long long> m;
vector<long long> v;
stack<long long> s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (int i = 1; i <= q; i++) {
    cin >> a[i];
    if (b[a[i]] == false) {
      b[a[i]] = true;
      s.push(a[i]);
      m[a[i]] = s.size();
    }
  }
  t = s.size();
  for (int i = 0; i < t; i++) {
    k = s.top();
    v.push_back(k);
    s.pop();
  }
  for (int i = 0; i < v.size(); i++) {
    s.push(v[i]);
  }
  v.clear();
  for (int i = 1; i <= q; i++) {
    h = m[a[i]];
    if (h == 1) {
      continue;
    } else {
      for (int j = 1; j < h; j++) {
        k = s.top();
        ans += w[k];
        s.pop();
        m[k] = j + 1;
        v.push_back(k);
      }
      s.pop();
      for (int j = 1; j < h; j++) {
        k = v.back();
        v.pop_back();
        s.push(k);
      }
      s.push(a[i]);
      m[a[i]] = 1;
    }
  }
  cout << ans << endl;
}
