#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 10;
int w[N], b[N];
int p[N];
bool u[N];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", w + i);
    for (int i = 1; i <= m; i++)
        scanf("%d", b + i);
    memset(p, 0, sizeof(p));
    long long ans = 0;
    for (int i = 1; i <= m; i++)
    {
        memset(u, 0, sizeof(u));
        for (int j = p[b[i]] + 1; j < i; j++)
            if (!u[b[j]])
                ans += w[b[j]], u[b[j]] = true;
        p[b[i]] = i;
    }
    printf("%lld", ans);
    return 0;
}
