#include <bits/stdc++.h>
int w[505], b[1005];
int v[505];
int main() {
  int n, m, sum = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  for (int i = 2; i <= m; i++) {
    memset(v, 0, sizeof(v));
    for (int j = i - 1; j > 0; j--) {
      if (b[j] == b[i]) break;
      if (!v[b[j]]) {
        sum += w[b[j]];
        v[b[j]] = 1;
      }
    }
  }
  printf("%d\n", sum);
}
