#include <bits/stdc++.h>
int w[505], read[1005];
int vis[505];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    memset(vis, 0, sizeof(vis));
    std::stack<int> st1, st2;
    for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
    for (int i = 1; i <= m; ++i) {
      scanf("%d", &read[i]);
      if (!vis[read[i]]) {
        st2.push(read[i]);
        vis[read[i]] = 1;
      }
    }
    while (!st2.empty()) {
      st1.push(st2.top());
      st2.pop();
    }
    int ans = 0;
    for (int i = 1; i <= m; ++i) {
      int weight = 0;
      while (st1.top() != read[i]) {
        weight += w[st1.top()];
        st2.push(st1.top());
        st1.pop();
      }
      int re = st1.top();
      st1.pop();
      while (!st2.empty()) {
        st1.push(st2.top());
        st2.pop();
      }
      st1.push(re);
      ans += weight;
    }
    printf("%d\n", ans);
  }
  return 0;
}
