#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, w[510], y[1010];
  bool b[510] = {0};
  cin >> n >> m;
  vector<int> ans;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    if (!b[x]) ans.push_back(x);
    b[x] = 1;
    y[i] = x;
  }
  long long jwb = 0;
  for (int i = 0; i < m; ++i) {
    auto it = ans.begin();
    while ((*it) != y[i]) {
      jwb += w[(*it)];
      ++it;
    }
    ans.erase(it);
    ans.insert(ans.begin(), y[i]);
  }
  cout << jwb << endl;
  return 0;
}
