#include <bits/stdc++.h>
int w[510], b[1010], c[510], d[510];
int main(void) {
  int i, j, k, n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    k = 1;
    long long ans = 0;
    memset(c, 0, sizeof(c));
    for (i = 1; i <= n; i++) scanf("%d", &w[i]);
    for (i = 1; i <= m; i++) {
      scanf("%d", &b[i]);
      if (c[b[i]] == 0) {
        d[k++] = b[i];
        c[b[i]] = 1;
      }
    }
    for (i = 1; i <= m; i++) {
      j = 1;
      while (d[j] != b[i]) ans += w[d[j++]];
      while (j > 1) {
        d[j] = d[j - 1];
        j--;
      }
      d[1] = b[i];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
