#include <bits/stdc++.h>
using namespace std;
ifstream fin("frac1.in");
ofstream fout("frac1.out");
class compare : public std::binary_function<double, double, bool> {
 public:
  compare(double arg = 1e-7) : e(arg) {}
  bool operator()(const double &left, const double &right) const {
    return (abs(left - right) > e) && (left < right);
  }
  double e;
};
inline int d_compare(double x, double y) {
  return (fabs(x - y) <= 1e-7) ? 0 : (x > y) ? 1 : -1;
}
inline int mod(long long x, int y) {
  if (y == 0) return x;
  if (x < 0) x = -x;
  if (x >= y) x %= y;
  return x;
}
inline int cmod(int x, int y) {
  if (y == 0) return x;
  if (x < 0) x += (abs(x) / y + 1) * y;
  if (x >= y) x = x % y;
  return x;
}
int Bcount(int mask) {
  int n = 0;
  while (mask) n += ((mask & -mask) != 0), mask &= ~(mask & -mask);
  return n;
}
inline bool Bstate(int mask, int idx) { return (mask & (1 << idx)); }
inline int B1(int mask, int idx) { return mask | (1 << idx); }
inline int B0(int mask, int idx) { return mask & ~(1 << idx); }
inline int drift(int mask, int n) { return mask & ((1 << n) - 1); }
void debugmask(int mask, int n) {
  for (int i = 0; i < n; i++) cout << Bstate(mask, i);
}
int dr[4] = {0, 0, -1, 1}, dc[4] = {-1, 1, 0, 0};
template <typename Ty>
void clear(Ty &q) {
  Ty empty;
  swap(q, empty);
}
int main() {
  deque<int> s;
  stack<int> temp;
  int n, m;
  int w[501];
  int vis[501] = {0};
  int o[1001];
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> w[i + 1];
  for (int i = 0; i < m; i++) {
    cin >> o[i];
    if (!vis[o[i]]) s.push_back(o[i]), vis[o[i]] = 1;
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    while (s.front() != o[i]) {
      ans += w[s.front()];
      temp.push(s.front());
      s.pop_front();
    }
    s.pop_front();
    while (!temp.empty()) {
      s.push_front(temp.top());
      temp.pop();
    }
    s.push_front(o[i]);
  }
  cout << ans << endl;
  return 0;
}
