#include <bits/stdc++.h>
using namespace std;
int book[600];
int w[600];
bool vis[600];
int plc[600];
int ord[1100];
int n, m;
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> ord[i];
  }
  int pp = 1;
  for (int i = 1; i <= m; i++) {
    if (!vis[ord[i]]) {
      plc[ord[i]] = pp++;
      vis[ord[i]] = true;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) plc[i] = pp++;
  }
  int sol = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (plc[j] < plc[ord[i]]) {
        sol += w[j];
        plc[j]++;
      }
    }
    plc[ord[i]] = 1;
  }
  cout << sol << endl;
}
