#include <bits/stdc++.h>
using namespace std;
int n, m, w[1000], b[2000];
int st[1000], pos, tmp[1000], pos2;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i) scanf("%d", &w[i]);
  for (int i = (0); i < (m); ++i) scanf("%d", &b[i]);
  int ans = 0;
  pos = 0;
  for (int i = (0); i < (m); ++i) {
    pos2 = 0;
    while ((pos > 0) && (st[pos - 1] != b[i])) {
      tmp[pos2] = st[pos - 1];
      ans += w[tmp[pos2]];
      --pos;
      ++pos2;
    }
    if (pos > 0) --pos;
    while (pos2 > 0) {
      st[pos++] = tmp[--pos2];
    }
    st[pos++] = b[i];
  }
  printf("%d\n", ans);
  return 0;
}
