#include <bits/stdc++.h>
using namespace std;
vector<int> V, P, R;
vector<bool> vis;
int main() {
  int N, M;
  cin >> N >> M;
  P.resize(N);
  V.resize(M);
  for (int i = 0; i < N; ++i) cin >> P[i];
  for (int i = 0; i < M; ++i) {
    cin >> V[i];
    V[i]--;
  }
  vis.assign(N, 0);
  for (int i = 0; i < M; ++i) {
    if (!vis[V[i]]) {
      R.push_back(V[i]);
      vis[V[i]] = true;
    }
  }
  long long ans = 0;
  for (int i = 0; i < M; ++i) {
    int pos = -1, act = V[i];
    for (int j = 0; j < N && pos == -1; ++j) {
      if (R[j] == act) pos = j;
    }
    for (int j = pos; j > 0; --j) {
      ans += P[R[j - 1]];
      R[j] = R[j - 1];
    }
    R[0] = act;
  }
  cout << ans << "\n";
}
