#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[505], sec[1005], l[505];
int main() {
  int ret = 0;
  bool v[505] = {0};
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i <= m; i++) {
    memset(v, 0, sizeof(v));
    scanf("%d", &sec[i]);
    for (int j = l[sec[i]] + 1; j < i; j++)
      if (!v[sec[j]]) {
        v[sec[j]] = 1;
        ret += w[sec[j]];
      }
    l[sec[i]] = i;
  }
  printf("%d\n", ret);
  return 0;
}
