#include <bits/stdc++.h>
using namespace std;
int n, m, a[1004], b[1004], ans;
bool q[1004];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= m; i++) {
    memset(q, false, sizeof(q));
    for (int j = i - 1; j; j--) {
      if (b[i] == b[j]) break;
      if (!q[b[j]]) q[b[j]] = true, ans += a[b[j]];
    }
  }
  cout << ans;
  return 0;
}
