#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 0.000000001;
const double PI = 3.141592653589793;
const long long LLINF = 99999999999999999LL;
const int MAX_N = 1005;
const int MOD = 1000000007;
int N, M;
int v[MAX_N], w[MAX_N], a[MAX_N];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) cin >> w[i];
  for (int i = 1; i <= M; ++i) cin >> v[i];
  int ans = 0;
  for (int i = 1; i <= M; ++i) {
    memset(a, 0, sizeof(a));
    for (int j = i - 1; j >= 1; --j) {
      if (v[j] == v[i]) break;
      if (a[v[j]] == 0) a[v[j]] = 1, ans += w[v[j]];
    }
  }
  cout << ans;
  return 0;
}
