#include <bits/stdc++.h>
using namespace std;
int a[510], b[1010], i, n, m, sm, x, j;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = -1;
  }
  for (i = 1; i <= m; i++) {
    cin >> x;
    for (j = 1; j <= n; j++)
      if (b[j] > b[x]) {
        sm += a[j];
      }
    b[x] = i;
  }
  cout << sm;
  return 0;
}
