#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int b[1010], c[1010], vis[1010];
struct node {
  int w, no;
} a[1010];
map<int, int> mm;
vector<int> vec;
int main() {
  vec.push_back(0);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    mm[i] = t;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 1; i <= m; i++) {
    if (vis[b[i]] == 0) {
      vec.push_back(b[i]);
      vis[b[i]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) vec.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    a[i].no = vec[i];
    a[i].w = mm[vec[i]];
  }
  long long ans = 0;
  int x, y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j].no == b[i]) {
        x = j;
        y = a[j].w;
        break;
      }
    }
    for (int j = x - 1; j > 0; j--) {
      ans += a[j].w;
      a[j + 1] = a[j];
    }
    a[1].no = b[i], a[1].w = y;
  }
  cout << ans << endl;
  return 0;
}
