#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int i, j, k;
  int n, m;
  cin >> n >> m;
  vector<long long> w(n), b(m), sum(n), stk;
  long long re = 0;
  for (int(i) = 0; (i) < (n); ++(i)) cin >> w[i];
  for (int(i) = 0; (i) < (m); ++(i)) cin >> b[i];
  for (int(i) = 0; (i) < (m); ++(i)) {
    b[i]--;
    if (count((stk).begin(), (stk).end(), b[i]) == 0) stk.push_back(b[i]);
  }
  for (int(i) = 0; (i) < (m); ++(i)) {
    for (int(j) = 0; (j) < (stk.size()); ++(j)) {
      if (stk[j] == b[i]) {
        stk.erase(stk.begin() + j);
        break;
      }
      re += w[stk[j]];
    }
    stk.insert(stk.begin(), b[i]);
  }
  cout << re << endl;
  return 0;
}
