#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n >> m;
  int w[n];
  for (i = 0; i < n; i++) {
    cin >> w[i];
  }
  int r[m], ans = 0;
  for (i = 0; i < m; i++) cin >> r[i];
  for (i = 1; i < m; i++) {
    int hs[512] = {0};
    for (j = i - 1; j >= 0; j--) {
      if (r[j] == r[i]) break;
      if (hs[r[j]] == 0) {
        ans += w[r[j] - 1];
        hs[r[j]] = 1;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
