#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10;
int n, t;
int w[N];
int d[N];
int use[510];
int main() {
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int j = 1; j <= t; j++) scanf("%d", &d[j]);
  int ans = 0;
  for (int i = 1; i <= t; i++) {
    memset(use, 0, sizeof(use));
    for (int j = i - 1; j; --j) {
      if (d[j] == d[i]) break;
      use[d[j]] = true;
    }
    for (int i = 1; i <= n; i++)
      if (use[i]) ans += w[i];
  }
  cout << ans << endl;
  return 0;
}
