#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000 + 10;
int w[max_n], b[max_n];
bool vis[max_n];
vector<int> v;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    b[i]--;
  }
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < m; i++)
    if (!vis[b[i]]) {
      vis[b[i]] = true;
      v.push_back(b[i]);
    }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int ind;
    for (int j = 0; j < v.size(); j++)
      if (v[j] == b[i]) {
        ind = j;
        break;
      }
    for (int j = ind - 1; j >= 0; j--) {
      ans += w[v[j]];
      swap(v[j], v[j + 1]);
    }
  }
  cout << ans << endl;
  return 0;
}
