#include <bits/stdc++.h>
using namespace std;
int w[1100], b[1100], vis[1100];
int main() {
  int n, i, j, k, l, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) scanf("%d", &w[i]);
    for (i = 1; i <= m; i++) scanf("%d", &b[i]);
    int ans = 0;
    for (i = 2; i <= m; i++) {
      memset(vis, false, sizeof(vis));
      for (j = i - 1; j >= 1; j--) {
        if (b[i] == b[j]) break;
        if (!vis[b[j]]) {
          ans += w[b[j]];
          vis[b[j]] = true;
        }
      }
    }
    printf("%d\n", ans);
  }
}
