#include <bits/stdc++.h>
using namespace std;
int x[504], p[1004];
vector<int> v;
int main() {
  int t, n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  set<int> st;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &p[i]);
    if (!st.count(p[i])) v.push_back(p[i]);
    st.insert(p[i]);
  }
  reverse(v.begin(), v.end());
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < v.size(); j++)
      if (v[j] == p[i]) {
        for (int k = j + 1; k < v.size(); k++) ans += x[v[k]];
        v.erase(v.begin() + j);
        v.push_back(p[i]);
        break;
      }
  }
  printf("%d\n", ans);
}
