#include <bits/stdc++.h>
using namespace std;
int weight[510], kanshu[1010], vis[510], st[510];
int main() {
  int booknum, day, p, ans, k, n, i, j;
  scanf("%d%d", &booknum, &day);
  for (i = 1; i <= booknum; i++) scanf("%d", &weight[i]);
  memset(vis, 0, sizeof(vis));
  p = 1;
  ans = 0;
  for (i = 1; i <= day; i++) {
    scanf("%d", &kanshu[i]);
    if (vis[kanshu[i]] == 0) {
      st[p++] = kanshu[i];
      vis[kanshu[i]] = 1;
    }
  }
  for (i = 2; i <= day; i++) {
    for (j = 1; j <= p; j++) {
      if (kanshu[i] == st[j])
        break;
      else
        ans += weight[st[j]];
    }
    n = j;
    for (j = n - 1; j >= 1; j--) st[j + 1] = st[j];
    st[1] = kanshu[i];
  }
  printf("%d\n", ans);
  return 0;
}
