#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Read(T &t) {
  int c = getchar(), f = 0;
  for (; c < '0' || c > '9'; c = getchar()) f = (c == '-');
  for (t = 0; c >= '0' && c <= '9'; c = getchar())
    t = (t << 3) + (t << 1) + (c ^ 48);
  if (f) t = -t;
}
int n, m, a[1003], b[1003], c[1003], ans;
int main() {
  Read(n), Read(m);
  for (register int i = 1; i <= n; ++i) Read(a[i]);
  for (register int i = 1; i <= m; ++i) Read(c[i]);
  for (register int i = 1; i <= m; ++i) {
    memset(b, 0, sizeof(b));
    for (register int j = i - 1; j; --j) {
      if (c[i] == c[j]) break;
      if (!b[c[j]]) b[c[j]] = 1, ans += a[c[j]];
    }
  }
  printf("%d", ans);
  return 0;
}
