#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = -1e18;
const long long INF = 1e18;
long long n, m, a[510], b[1010], c[510], us[510], ans, k;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  k = 1;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    if (us[b[i]] == 0) {
      us[b[i]] = 1;
      c[k++] = b[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (us[i] == 0) {
      c[k++] = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (b[i] == c[j]) {
        for (int k = j; k > 1; k--) {
          c[k] = c[k - 1];
        }
        c[1] = b[i];
        break;
      }
      ans += a[c[j]];
    }
  }
  cout << ans;
  return 0;
}
