#include <bits/stdc++.h>
using namespace std;
int w[510];
int b[1100];
int a[510], f[510];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  memset(f, 0, sizeof(f));
  int tot = 0;
  for (int i = 1; i <= m; i++)
    if (!f[b[i]]) {
      f[b[i]] = 1;
      a[++tot] = b[i];
    }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int j;
    for (j = 1; j <= n; j++) {
      if (a[j] == b[i]) break;
      ans += w[a[j]];
    }
    int t = a[j];
    for (int k = j; k > 1; k--) a[k] = a[k - 1];
    a[1] = t;
  }
  printf("%d\n", ans);
  return 0;
}
