#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, a[505] = {0}, b[1005] = {0}, ans = 0;
  scanf("%I64d%I64d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%I64d", &b[i]);
    long long int s = 0;
    bool visited[505] = {false};
    for (j = i - 1; j > 0; j--) {
      if (b[j] == b[i]) break;
      if (visited[b[j]]) continue;
      s += (a[b[j]]);
      visited[b[j]] = true;
    }
    ans += s;
  }
  printf("%I64d\n", ans);
  return 0;
}
