#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
long long ans;
bool used[N + 10];
int n, m, cnt, w[N + 10], b[N + 10], c[N + 10], book[N + 10];
struct node {
  int x, y, z;
  node() {}
  node(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
} a[N + 10];
inline bool cmp(const node &a, const node &b) { return a.x * a.y > b.x * b.y; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]), c[b[i]]++;
  for (int i = 1; i <= n; ++i) a[i] = node(c[i], w[i], i);
  for (int i = 1; i <= m; ++i)
    if (!used[b[i]]) book[++cnt] = b[i], used[b[i]] = 1;
  for (int i = 1; i <= m; ++i) {
    int j;
    for (j = 1;; ++j) {
      if (book[j] == b[i]) break;
      ans += w[book[j]];
    }
    for (int k = j - 1; k >= 1; --k) book[k + 1] = book[k];
    book[1] = b[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
