#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
const int mod = 1000000009;
int w[510], b[1010], us[510];
vector<int> v;
int main() {
  int n, m, i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> w[i];
  for (j = 1; j <= m; j++) {
    cin >> b[j];
    if (!us[b[j]]) {
      v.push_back(b[j]);
      us[b[j]] = 1;
    }
  }
  for (i = 1; i <= n; i++)
    if (!us[i]) {
      v.push_back(i);
      us[i] = 1;
    }
  int ans = 0;
  for (j = 1; j <= m; j++) {
    for (i = 0; i < v.size(); i++) {
      if (v[i] == b[j]) break;
      ans += w[v[i]];
    }
    while (i > 0) v[i] = v[i - 1], i--;
    v[0] = b[j];
  }
  cout << ans;
}
