#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int w[n], b[m], ans = 0;
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = 0; i < m; i++) {
    map<int, int> mp;
    for (int j = i - 1; j >= 0; j--) {
      if (mp[b[j]]) continue;
      if (b[j] == b[i]) break;
      ans += w[b[j] - 1];
      mp[b[j]]++;
    }
  }
  cout << ans << endl;
}
