50 50
75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99
26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41 2 7 9 24 27 23 3 44 15 14
 10 10
61 59 97 16 2 94 57 48 91 93
2 8 6 5 3 1 3 4 9 10
 2 1
1 2
1
 3 3
10 20 30
1 2 3
 50 60
86 57 45 93 17 12 40 10 47 80 18 80 3 9 6 55 13 99 5 76 4 70 100 55 27 91 71 3 65 93 41 74 80 56 90 50 58 13 71 9 47 52 26 73 72 21 15 81 88 28
40 32 5 16 49 23 3 17 14 10 1 15 1 21 28 22 13 45 12 25 44 48 46 32 36 43 11 8 49 7 7 35 10 14 39 4 42 10 30 27 1 17 31 15 8 41 44 33 25 26 19 18 29 37 50 6 36 38 47 9
 2 7
20 30
1 1 1 2 2 2 2
 2 2
10 12
2 1
 5 1
16 87 36 16 81
3
 2 3
20 30
1 1 1
 2 10
39 26
1 1 2 2 2 2 2 2 1 2

63929
 2137
 0
 40
 62514
 20
 12
 0
 0
 104

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int mod = 998244353;
const int nag = 2e5 + 5;
template <typename T>
void add(T& a, T b) {
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <typename T>
void mul(T& a, T b) {
  a = a * b % mod;
}
template <typename T>
void up_self(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
string find_largest_pref_palindrome(const string& a) {
  string second = a;
  reverse(second.begin(), second.end());
  second = a + "%" + second;
  int c = 0;
  vector<int> pref(2 * ((int)a.size()) + 2);
  for (int i = 1; i < second.size(); i++) {
    while (c != 0 && second[i] != second[c]) c = pref[c - 1];
    if (second[i] == second[c]) c++;
    pref[i] = c;
  }
  return second.substr(0, c);
}
long long int binexpomodulo(long long int x, long long int y) {
  long long int res = 1;
  x %= mod;
  if (!x) return 0;
  while (y) {
    if (y & 1) {
      mul(res, x);
    }
    mul(x, x);
    y >>= 1;
  }
  return res;
}
long long int nCrInOr(long long int n, long long int r) {
  long long int res = 1;
  if (r > n - r) r = n - r;
  long long int rin = 1;
  for (long long int i = 1; i <= r; i++) rin = (rin * i) % mod;
  rin = binexpomodulo(rin, mod - 2);
  for (long long int i = 1; i <= r; i++) res = (res * (n - i + 1)) % mod;
  res = (res * rin) % mod;
  return res;
}
vector<long long int> fac, ifac;
void precompute(long long int n) {
  fac.resize(n + 1, 1);
  ifac.resize(n + 1);
  for (long long int i = 2; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
  ifac[n] = binexpomodulo(fac[n], mod - 2);
  for (long long int i = n - 1; i >= 0; i--)
    ifac[i] = (ifac[i + 1] * (i + 1)) % mod;
}
long long int nCr(long long int n, long long int r) {
  return fac[n] * (ifac[n - r]) % mod * (ifac[r]) % mod;
}
int msb_pos(long long int n) {
  int ans;
  for (int i = 0; i < 64; i++)
    if (n & (1LL << i)) ans = i + 1;
  return ans;
}
long long int totient(long long int n) {
  long long int ans = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans -= (ans / i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n >= 2) {
    ans -= ans / n;
  }
  return ans;
}
int lis(vector<long long int> a, int n) {
  vector<long long int> dp(n + 1, 1e18);
  dp[0] = -1e18;
  for (int i = 0; i < n; i++) {
    int p = (int)(lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
    if (dp[p - 1] < a[i] && a[i] < dp[p]) dp[p] = a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] != 1e18) ans = i;
  }
  return ans;
}
bool is_prime(int n) {
  if (n == 2) return true;
  if (n & 1 ^ 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int get_(vector<long long int>& a, int pos) {
  long long int res = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    res += a[pos];
  }
  return res;
}
void upd(vector<long long int>& a, int pos, int val) {
  for (; pos < a.size(); pos = (pos | (pos + 1))) a[pos] += val;
}
bool sorter(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> weights(n + 1), order(m + 1);
  vector<bool> used(n + 1);
  for (int i = 1; i < n + 1; i++) cin >> weights[i];
  int pos = 1;
  vector<int> pile(n + 1);
  for (int i = 1; i < m + 1; i++) {
    cin >> order[i];
    if (!used[order[i]]) used[order[i]] = true, pile[pos++] = weights[order[i]];
  }
  for (int i = 1; i < n + 1; i++)
    if (!used[i]) pile[pos++] = i;
  long long int ans = 0;
  for (int i = 1; i < m + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      if (pile[j] == order[i]) {
        for (int k = j; k > 1; k--) {
          pile[k] = pile[k - 1];
        }
        pile[1] = order[i];
        break;
      }
      ans += weights[pile[j]];
    }
  }
  cout << ans << "\n";
  return 0;
}
