#include <bits/stdc++.h>
using namespace std;
int w[1010];
int b[1010];
int vis[1010];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) {
      cin >> w[i];
    }
    for (int j = 0; j < m; j++) {
      cin >> b[j];
    }
    stack<int> s1;
    stack<int> s2;
    long long ans = 0;
    long long tmp;
    memset(vis, 0, sizeof(vis));
    long long sum = 0;
    int d;
    for (int i = 0; i < m; i++) {
      if (!vis[b[i]]) {
        ans += (long long)sum;
        s1.push(b[i]);
        sum += (long long)w[b[i]];
        vis[b[i]] = 1;
      } else {
        tmp = 0;
        while (s1.top() != b[i]) {
          s2.push(s1.top());
          s1.pop();
          tmp += w[s2.top()];
        }
        d = s1.top();
        s1.pop();
        while (!s2.empty()) {
          s1.push(s2.top());
          s2.pop();
        }
        s1.push(d);
        ans += tmp;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
