#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return SQR(POW(B, P / 2));
}
template <typename T>
inline T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
inline T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int arr[510], x, vis[1510], stk[1510];
int main() {
  int n, m, i, j = 1000, top, res;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int p = n, id;
  top = 0, res = 0;
  for (int k = 1; k <= m; k++) {
    cin >> x;
    if (vis[x]) {
      for (int l = p; l < 1500; l++) {
        if (stk[l] == x) {
          id = l;
          break;
        }
      }
      for (int l = id; l > p + 1; l--) {
        res += arr[stk[l - 1]];
        swap(stk[l - 1], stk[l]);
      }
    } else {
      stk[p--] = x;
      res += top;
      top += arr[x];
      vis[x] = 1;
    }
  }
  cout << res << endl;
  return 0;
}
