#include <bits/stdc++.h>
using namespace std;
struct node {
  int lis;
  struct node *link;
};
int n, m, i, j, sum, ans;
int readlist[1005], w[505], vis[505];
node *initial() {
  node *head, *p1, *p2;
  head = (node *)malloc(sizeof(node));
  head->link = NULL;
  head->lis = 0;
  p1 = head;
  for (int i = 1; i <= m; i++) {
    cin >> readlist[i];
    if (vis[readlist[i]] == 0) {
      p2 = (node *)malloc(sizeof(node));
      p2->lis = readlist[i];
      p2->link = NULL;
      p1->link = p2;
      p1 = p2;
      vis[readlist[i]] = 1;
    }
  }
  return (head);
}
void append(node *head, int v) {
  node *ptr;
  ptr = (node *)malloc(sizeof(node));
  ptr->lis = v;
  ptr->link = head->link;
  head->link = ptr;
}
void delet(node *pf) {
  node *ptr;
  ptr = pf->link;
  if (ptr != NULL) {
    pf->link = ptr->link;
    free(ptr);
  }
}
void search(node *head, int v) {
  node *ptr;
  ptr = (node *)malloc(sizeof(node));
  ptr = head;
  while (1) {
    sum += w[ptr->lis];
    if (ptr->link->lis == v) break;
    ptr = ptr->link;
  }
  delet(ptr);
  append(head, v);
}
void print(node *head) {
  node *ptr;
  ptr = (node *)malloc(sizeof(node));
  ptr = head->link;
  while (1) {
    cout << ptr->lis << " ";
    if (ptr->link == NULL) break;
    ptr = ptr->link;
  }
  cout << endl;
}
int main() {
  while (cin >> n >> m) {
    memset(w, 0, sizeof(w));
    memset(readlist, 0, sizeof(readlist));
    memset(vis, 0, sizeof(vis));
    sum = 0;
    for (i = 1; i <= n; i++) cin >> w[i];
    node *head;
    head = initial();
    for (i = 1; i <= m; i++) {
      search(head, readlist[i]);
    }
    cout << sum << endl;
  }
  return 0;
}
