#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, w[600], b[1100], i, j, rk[600];
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  int cnt = 0, vis[550];
  memset(vis, 0, sizeof(vis));
  for (i = 0; cnt < n && i < m; i++) {
    if (!vis[b[i]]) {
      vis[b[i]] = 1;
      rk[cnt] = b[i];
      cnt++;
    }
  }
  int tmp, tt;
  int res = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (rk[j] == b[i]) {
        tmp = j;
      }
    }
    for (j = 0; j < tmp; j++) {
      res += w[rk[j]];
    }
    tt = rk[tmp];
    for (j = tmp; j > 0; j--) {
      rk[j] = rk[j - 1];
    }
    rk[0] = tt;
  }
  printf("%d\n", res);
  return 0;
}
