#include <bits/stdc++.h>
using namespace std;
int color[510], arr[510], wrr[510], brr[1010];
int main() {
  long long n, m, i, l, ans, x, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> wrr[i];
  }
  l = 0;
  for (i = 1; i <= m; i++) {
    cin >> brr[i];
    if (color[brr[i]] == 0) {
      l++;
      arr[l] = brr[i];
      color[brr[i]] = 1;
    }
  }
  ans = 0;
  for (i = 1; i <= m; i++) {
    x = 1;
    while (arr[x] != brr[i]) {
      x++;
    }
    for (j = x; j > 1; j--) {
      ans += wrr[arr[j - 1]];
      swap(arr[j], arr[j - 1]);
    }
  }
  cout << ans;
  return 0;
}
