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