#include <bits/stdc++.h>
using namespace std;
int t, cs, n, m, k;
int a[505];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  vector<int> v, s;
  map<int, int> mp;
  while (m--) {
    scanf("%d", &k);
    s.push_back(k);
    if (mp[k]) continue;
    mp[k] = 1;
    v.push_back(k);
  }
  stack<int> st;
  for (int i = v.size() - 1; i >= 0; i--) st.push(v[i]);
  int sum = 0;
  stack<int> tmp = st;
  for (int i = 0; i < s.size(); i++) {
    stack<int> q;
    q.push(s[i]);
    while (st.top() != s[i]) {
      sum += a[st.top()];
      q.push(st.top());
      st.pop();
    }
    st.pop();
    while (!q.empty()) {
      st.push(q.top());
      q.pop();
    }
    tmp = st;
  }
  printf("%d", sum);
  return 0;
}
