#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int w[505];
  int b[1005];
  for (int i = 0; i < n; i++) scanf("%d", &w[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    b[i]--;
  }
  int ans = 0;
  int sz = 0;
  int ord[505];
  int vis[505];
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < m; i++) {
    if (vis[b[i]]) {
      int sum = 0;
      for (int j = 0; j < sz; j++) {
        if (ord[j] == b[i]) {
          for (int k = j; k >= 1; k--) ord[k] = ord[k - 1];
          ord[0] = b[i];
          break;
        } else {
          sum += w[ord[j]];
        }
        assert(j != (sz - 1));
      }
      ans += sum;
    } else {
      vis[b[i]] = true;
      ord[sz++] = b[i];
      i--;
    }
  }
  cout << ans << endl;
  return 0;
}
