#include <bits/stdc++.h>
using namespace std;
int a[512], b[512], n, m, i, t1, t2, ans, sum, t, c[512];
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (i = 0; i < m; i++) {
    scanf("%d", &t);
    while (t1 && a[t1 - 1] != t) {
      b[t2++] = a[--t1];
      ans += c[a[t1]];
    }
    if (t1) t1--;
    while (t2) a[t1++] = b[--t2];
    a[t1++] = t;
  }
  printf("%d\n", ans);
  return 0;
}
