#include <bits/stdc++.h>
using namespace std;
int find(vector<int> &v, int val) {
  for (int i = 0; i < v.size(); i++)
    if (v[i] == val) return i;
  return -1;
}
void pr(vector<int> &v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> w(n);
  for (int i = 0; i < n; i++) cin >> w[i];
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    b[i]--;
  }
  vector<int> s;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int f = find(s, b[i]);
    if (f == -1) {
      f = s.size();
      s.push_back(b[i]);
    }
    for (int i = 0; i < f; i++) sum += w[s[i]];
    int book = s[f];
    for (int i = f; i > 0; i--) {
      s[i] = s[i - 1];
    }
    s[0] = book;
  }
  cout << sum;
  return 0;
}
