#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, w, b;
  cin >> n >> m;
  vector<long long> weights, read;
  deque<long long> order;
  weights.push_back(0);
  for (int i = (1); i <= (n); i++) {
    cin >> w;
    weights.push_back(w);
  }
  bool check[505];
  read.push_back(0);
  memset(check, 0, sizeof(check));
  for (int i = (1); i <= (m); i++) {
    cin >> b;
    read.push_back(b);
    if (!check[b]) {
      check[b] = 1;
      order.push_back(b);
    }
  }
  long long ans = 0;
  for (int i = (1); i <= (m); i++) {
    long long toread = read[i];
    long long sum = 0;
    for (auto it = order.begin(); it != order.end(); it++) {
      if (*it == toread) {
        ans += sum;
        order.erase(it);
        order.push_front(toread);
        break;
      } else {
        sum += weights[*it];
      }
    }
  }
  cout << ans;
}
