#include <bits/stdc++.h>
int main() {
  int n, i, j, m, tot;
  int weg[555], hastnd[555], book[1010];
  while (scanf("%d%d", &n, &m) != EOF) {
    tot = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &weg[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &book[i]);
    }
    for (i = 1; i < m; i++) {
      memset(hastnd, 0, sizeof(hastnd));
      for (j = i - 1; j >= 0; j--) {
        if (book[i] == book[j])
          break;
        else if (hastnd[book[j]] == 0) {
          hastnd[book[j]]++;
          tot += weg[book[j]];
        }
      }
    }
    printf("%d\n", tot);
  }
  return 0;
}
