#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010];
int v[1010];
int vis[1010];
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> v[i];
  }
  int ac = 0;
  for (int i = 0; i < m; ++i) {
    memset(vis, 0, sizeof vis);
    for (int j = i - 1; j >= 0; --j) {
      if (v[i] == v[j]) {
        break;
      } else if (!vis[v[j]]) {
        vis[v[j]] = 1;
        ac += a[v[j]];
      }
    }
  }
  cout << ac << "\n";
  return 0;
}
