#include <bits/stdc++.h>
using namespace std;
int fix[100001];
int a[100001];
int b[100001];
int n, m, k, i, j, res, sum;
vector<int> v;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  for (i = 1; i <= m; i++)
    if (!fix[b[i]]) {
      v.push_back(b[i]), fix[b[i]] = 1;
    }
  for (i = 1; i <= m; i++) {
    sum = 0;
    for (j = 0; j < v.size(); j++) {
      if (v[j] == b[i]) {
        res += sum;
        for (int I = j; I >= 1; I--) v[I] = v[I - 1];
        v[0] = b[i];
        break;
      }
      sum += a[v[j]];
    }
  }
  cout << res;
}
