#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const double eps = 1e-8;
const int MAXN = 1100 + 10;
const int MOD = 1000007;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int w[MAXN], brow[MAXN], vis[MAXN];
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (i = 1; i <= m; i++) scanf("%d", &brow[i]);
  int ans = 0;
  for (i = 1; i <= m; i++) {
    memset(vis, 0, sizeof(vis));
    for (j = i - 1; j > 0; j--) {
      if (brow[i] == brow[j]) break;
      if (!vis[brow[j]]) {
        vis[brow[j]] = 1;
        ans += w[brow[j]];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
