#include <bits/stdc++.h>
using namespace std;
const int maxn = 105000;
const long long inf = 99999999999999;
const long long mod = 1000000007;
int n, m;
int w[maxn], b[maxn];
int biaoji[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int j = 1; j <= m; j++) cin >> b[j];
  int ans = 0;
  for (int i = 2; i <= m; i++) {
    memset(biaoji, 0, sizeof(biaoji));
    for (int j = i - 1; j >= 1; j--) {
      if (b[i] == b[j])
        break;
      else {
        if (!biaoji[b[j]]) {
          biaoji[b[j]] = 1;
          ans += w[b[j]];
        }
      }
    }
  }
  cout << ans << endl;
}
