#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000 + 100;
long long w[MAXN], arr[MAXN];
long long javab[MAXN];
bool mrk[MAXN];
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> w[i];
  for (long long i = 0; i < m; i++) {
    cin >> arr[i];
    arr[i]--;
  }
  for (long long i = 0; i < MAXN; i++) javab[i] = -1;
  long long pt = 0;
  long long cnt = 0;
  for (long long i = 0; i < m; i++) {
    for (long long i = 0; i < n; i++) mrk[i] = 0;
    bool h = 0;
    for (long long j = pt - 1; j >= 0; j--)
      if (javab[j] == arr[i]) {
        h = 1;
        for (long long k = 0; k < n; k++)
          if (mrk[k]) cnt += w[k];
        break;
      } else
        mrk[javab[j]] = 1;
    javab[pt++] = arr[i];
    if (!h)
      for (long long k = 0; k < n; k++)
        if (mrk[k]) cnt += w[k];
  }
  cout << cnt << '\n';
  return 0;
}
