#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int w[2005], b[2005], f[2005], pos[2005];
int read(int pos) {
  int res = 0;
  while (pos) {
    res += f[pos];
    pos -= pos & -pos;
  }
  return res;
}
void update(int pos, int val) {
  while (pos < 2005) {
    f[pos] += val;
    pos += pos & -pos;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, cnt, res;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  cnt = res = 0;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    if (!pos[b[i]]) {
      pos[b[i]] = m + cnt + 1;
      update(pos[b[i]], w[b[i]]);
      ++cnt;
    }
  }
  for (int i = 0; i < m; ++i) {
    res += read(pos[b[i]] - 1);
    update(pos[b[i]], -w[b[i]]);
    pos[b[i]] = m - i;
    update(pos[b[i]], w[b[i]]);
  }
  cout << res << "\n";
  return 0;
}
