#include <bits/stdc++.h>
int weights[10000];
int order[10000];
int set[10000];
struct llist {
  int data;
  int index;
  struct llist *next;
};
void push(struct llist **head, int data, int index) {
  struct llist *newnode = (struct llist *)malloc(sizeof(struct llist));
  newnode->data = data;
  newnode->index = index;
  newnode->next = *head;
  *head = newnode;
}
void pop(struct llist **head) {
  struct llist *tempnode = *head;
  *head = (*head)->next;
  free(tempnode);
}
void rmv(struct llist *curr) {
  struct llist *next = curr->next->next;
  free(curr->next);
  curr->next = next;
}
int w_search(struct llist **head, int match) {
  int i = 0;
  int total_data = 0;
  push(head, 0, match);
  struct llist *prevnode = *head;
  struct llist *tempnode = prevnode->next;
  while (tempnode != NULL && tempnode->index != match) {
    total_data += tempnode->data;
    prevnode = tempnode;
    tempnode = prevnode->next;
  }
  (*head)->data = tempnode->data;
  rmv(prevnode);
  return total_data;
}
void reverse(struct llist **head) {
  struct llist *nextnode = *head;
  struct llist *currnode = *head;
  struct llist *prevnode = NULL;
  while (nextnode != NULL) {
    nextnode = currnode->next;
    currnode->next = prevnode;
    prevnode = currnode;
    currnode = nextnode;
  }
  *head = prevnode;
}
int main() {
  struct llist *head = NULL;
  int n, m;
  scanf("%d%d", &n, &m);
  int i, j;
  for (i = 1; i <= n; i++) scanf("%d", &weights[i]);
  for (i = 1; i <= m; i++) scanf("%d", &order[i]);
  int totalset = 0;
  for (i = 1; i <= m && totalset != n; i++) {
    if (set[order[i]] == 0) {
      push(&head, weights[order[i]], order[i]);
      set[order[i]] = 1;
      ;
      totalset++;
    }
  }
  reverse(&head);
  int totalweight = 0;
  for (i = 1; i <= m; i++) {
    totalweight += w_search(&head, order[i]);
  }
  printf("%d\n", totalweight);
}
