#include <bits/stdc++.h>
using namespace std;
long long kl = 0, N, M, a[10000], b[10000], st[10000], in[10000], vt = 1,
          k[10000], res = 0;
int main() {
  cin >> M >> N;
  for (int i = 1; i <= M; i++) cin >> a[i];
  for (int i = 1; i <= N; i++) {
    cin >> b[i];
    if (in[b[i]] == 0) {
      in[b[i]] = vt + 1;
      st[vt++] = b[i];
      k[vt - 1] = kl;
      kl += a[b[i]];
    }
  }
  for (int i = 1; i <= N; i++) {
    int j;
    for (j = 1; j <= M; j++)
      if (st[j] == b[i]) break;
    res += k[j];
    for (int tg = j; tg > 1; tg--) {
      st[tg] = st[tg - 1];
      k[tg] = k[tg - 1] + a[b[i]];
    }
    k[1] = 0;
    st[1] = b[i];
  }
  cout << res;
}
