#include <bits/stdc++.h>
int stack1[505], stack2[505], w[505];
int main() {
  int n, m, cnt1 = 0, cnt2 = 0;
  scanf("%d %d", &n, &m);
  int ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 0; i < m; i++) {
    int a;
    scanf("%d", &a);
    for (; cnt1; cnt1--) {
      if (stack1[cnt1 - 1] != a) {
        ans += w[stack1[cnt1 - 1]];
        stack2[cnt2++] = stack1[cnt1 - 1];
      } else {
        cnt1--;
        break;
      }
    }
    while (cnt2) {
      stack1[cnt1++] = stack2[cnt2 - 1];
      cnt2--;
    }
    stack1[cnt1++] = a;
  }
  printf("%d\n", ans);
}
