#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int w[MAXN], q[MAXN];
int main() {
  int n, m, b, tot = 0, ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  while (m--) {
    scanf("%d", &b);
    int idx;
    for (idx = 0; idx < tot; ++idx)
      if (q[idx] == b) break;
    if (idx < tot) {
      for (++idx; idx < tot; ++idx) {
        ans += w[q[idx]];
        swap(q[idx], q[idx - 1]);
      }
    } else {
      for (int i = 0; i < tot; ++i) ans += w[q[i]];
      q[tot++] = b;
    }
  }
  printf("%d", ans);
}
