#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, w[505], b[1005], order[505], vis[505];
  memset(w, 0, sizeof(w));
  memset(b, 0, sizeof(b));
  memset(vis, 0, sizeof(vis));
  memset(order, 0, sizeof(order));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
  }
  int k = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    if (vis[b[i]] == 0) {
      order[k] = b[i];
      vis[b[i]] = 1;
      k++;
    }
  }
  int sum = 0, j;
  for (int i = 1; i <= m; i++) {
    for (j = 1; order[j] != b[i]; j++) {
      sum += w[order[j]];
    }
    order[0] = order[j];
    for (int u = j - 1; u >= 1; u--) {
      order[u + 1] = order[u];
    }
    order[1] = order[0];
    order[0] = 0;
  }
  printf("%d\n", sum);
  return 0;
}
