#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, i, j = 0, w[510] = {0}, color[510] = {0}, s = 0, t, t1, t2,
                a[1006] = {0}, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> w[i];
  for (i = 0; i < m; i++) {
    cin >> t;
    if (!color[t]) {
      a[j++] = t;
      color[t] = 1;
    }
    t2 = t1 = a[0];
    for (k = 0; k < j; k++) {
      if (t2 != t) {
        s += w[t1 - 1];
        t2 = a[k + 1];
        a[k + 1] = t1;
        t1 = t2;
      } else
        break;
    }
    a[0] = t;
  }
  cout << s << endl;
  return 0;
}
