#include <bits/stdc++.h>
using namespace std;
long w[504], v[1003], b[506];
int main() {
  long n, m;
  cin >> n >> m;
  for (long i = 1; i <= n; i++) cin >> w[i];
  for (long i = 1; i <= m; i++) cin >> v[i];
  long long int ans = 0;
  for (long i = 1; i <= n; i++) {
    long str = 0;
    for (long j = 1; j <= n; j++) {
      b[j] = 0;
    }
    long long int s = 0;
    for (long j = 1; j <= m; j++) {
      long h = v[j];
      if (h != i) {
        if (b[h] <= str) {
          b[h] = j;
          s = s + w[h];
        }
      } else {
        ans = ans + s;
        s = 0;
        str = j;
      }
    }
  }
  cout << ans << endl;
}
