#include <bits/stdc++.h>
using namespace std;
int n, m, re;
int w[505], d[1005];
bool ok[505];
int use[505], id;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i];
    d[i]--;
    if (!ok[d[i]]) {
      use[id++] = d[i];
      ok[d[i]] = true;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (use[j] == d[i]) {
        for (int k = j; k > 0; k--) {
          use[k] = use[k - 1];
        }
        use[0] = d[i];
        break;
      }
      re += w[use[j]];
    }
  }
  cout << re;
  return 0;
}
