#include <bits/stdc++.h>
int main() {
  int kn[1100];
  int dni[1100];
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", (kn + i));
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", (dni + i));
  }
  int s = 0;
  for (int i = 1; i <= m; i++) {
    int sh = 0;
    int verx[1100];
    for (int i = 0; i < 1100; i++) {
      verx[i] = 0;
    }
    int j = i - 1;
    for (;;) {
      if (j == 0) {
        break;
      }
      if (dni[j] == dni[i]) {
        break;
      }
      verx[dni[j]] = 1;
      j--;
    }
    for (int i = 0; i < 1100; i++) {
      if (verx[i] == 1) {
        sh += kn[i];
      }
    }
    s += sh;
  }
  printf("%d", s);
  return 0;
}
