#include <bits/stdc++.h>
using namespace std;
int w[501];
int b[1001];
bool u[501];
int stck[501];
int main() {
  ios::sync_with_stdio(true);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> w[i];
  ;
  for (int i = 0; i < m; i++) cin >> b[i];
  ;
  int sti = 0;
  for (int i = 0; i < m; i++) {
    if (!u[b[i]]) {
      stck[sti++] = b[i];
      u[b[i]] = true;
    }
  }
  int weight = 0;
  for (int i = 0; i < m; i++) {
    bool swapf = false;
    for (int j = sti - 1; j >= 0; j--) {
      if (swapf) {
        weight += w[stck[j] - 1];
        swap(stck[j], stck[j + 1]);
      } else if (stck[j] == b[i])
        swapf = true;
    }
  }
  cout << weight;
  cout << "\n";
  return 0;
}
