#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
template <class T>
T jog(T a, T b) {
  return a + b;
}
template <class T>
T bog(T a, T b) {
  return a - b;
}
template <class T>
T gon(T a, T b) {
  return a * b;
}
template <class T>
T sq(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
T power(T a, T p) {
  int res = 1, x = a;
  while (p) {
    if (p & 1) res = res * x;
    x = x * x;
    p >>= 1;
  }
  return res;
}
template <class T>
T cordinatlenth(T a, T b, T c, T d) {
  return sqrt(sq(a - c) + sq(b - d));
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long bigmod(long long a, long long p, long long mod) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    p >>= 1;
  }
  return res;
}
int diraction1[] = {-1, 0, 0, 1, 1, -1, -1, 1};
int diraction2[] = {0, -1, 1, 0, 1, -1, 1, -1};
int horsed1[] = {-2, -2, -1, 1, 2, 2, 1, -1};
int horsed2[] = {1, -1, -2, -2, -1, 1, 2, 2};
void input();
int n, m, w[510], b[1010], st[1010];
long long ans;
int main() {
  input();
  return 0;
}
void input() {
  scanf("%d %d", &n, &m);
  ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  memset(st, -1, sizeof(st));
  int ind = 0;
  st[ind++] = b[0];
  for (int i = 1; i < m; i++) {
    int flag = 1;
    for (int j = 0; j < ind; j++) {
      if (st[j] == b[i]) {
        for (int k = j; k > 0; k--) st[k] = st[k - 1];
        st[0] = b[i];
        flag = 0;
        break;
      }
      ans += w[st[j]];
    }
    if (flag) {
      ind++;
      for (int j = ind; j > 0; j--) st[j] = st[j - 1];
      st[0] = b[i];
    }
  }
  cout << ans << endl;
}
