#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int MAXM = 1010;
int n, m;
int w[MAXN], b[MAXM];
int v[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int sum, ans;
  sum = ans = 0;
  for (int i = 1; i <= m; i++) {
    sum = 0;
    memset(v, 0, sizeof(v));
    for (int j = i - 1; j > 0 && b[j] != b[i]; j--)
      if (v[b[j]] == 0) {
        sum += w[b[j]];
        v[b[j]] = 1;
      }
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}
