50 50
75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99
26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41 2 7 9 24 27 23 3 44 15 14
 10 10
61 59 97 16 2 94 57 48 91 93
2 8 6 5 3 1 3 4 9 10
 2 1
1 2
1
 3 3
10 20 30
1 2 3
 50 60
86 57 45 93 17 12 40 10 47 80 18 80 3 9 6 55 13 99 5 76 4 70 100 55 27 91 71 3 65 93 41 74 80 56 90 50 58 13 71 9 47 52 26 73 72 21 15 81 88 28
40 32 5 16 49 23 3 17 14 10 1 15 1 21 28 22 13 45 12 25 44 48 46 32 36 43 11 8 49 7 7 35 10 14 39 4 42 10 30 27 1 17 31 15 8 41 44 33 25 26 19 18 29 37 50 6 36 38 47 9
 2 7
20 30
1 1 1 2 2 2 2
 2 2
10 12
2 1
 5 1
16 87 36 16 81
3
 2 3
20 30
1 1 1
 2 10
39 26
1 1 2 2 2 2 2 2 1 2

63929
 2137
 0
 40
 62514
 20
 12
 0
 0
 104

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;


public class Main implements Runnable {

  private void solve(QuickScanner in, PrintWriter out) {
    int n = in.nextInt();
    int m = in.nextInt();
    int[] weight = new int[n];
    for (int i = 0; i < n; i++) {
      weight[i] = in.nextInt();
    }
    int[] seq = new int[m];
    for (int i = 0; i < m; i++) {
      seq[i] = in.nextInt() - 1;
    }
    ArrayList<Integer> state = new ArrayList<Integer>();
    Set<Integer> st = new HashSet<Integer>();
    for (int i = 0; i < m; i++) {
      if (!st.contains(seq[i])) {
        state.add(seq[i]);
        st.add(seq[i]);
      }
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
      int book = seq[i];
      int pos = -1;
      for (int j = 0; j < state.size(); j++) {
        if (state.get(j) == book) {
          pos = j;
          break;
        }
      }
      for (int j = 0; j < pos; j++) {
        ans += weight[state.get(j)];
      }
      state.remove(pos);
      state.add(0, book);
    }
    out.println(ans);
  }

  private static final double EPS = 1E-8;
  private static final long MOD = 1000000007L;

  private static int signum(double val) {
    if (Math.abs(val) < EPS) {
      return 0;
    }
    return val > 0 ? 1 : -1;
  }

  private static int cmp(double x, double y) {
    return signum(x - y);
  }

  private static void debug(Object... objects) {
    System.err.println(Arrays.deepToString(objects));
  }

  private static void assertTrue(boolean cond) {
    if (!cond) {
      throw new AssertionError();
    }
  }

  /**
   * A util function to get current time. This is often used in some search or random algorithm for
   * limit program run time.
   * 
   * @return currentTime in MS.
   */
  private static long currentTime() {
    return System.currentTimeMillis();
  }

  private class QuickScanner {
    private BufferedReader bufferedReader = null;
    private StringTokenizer stringTokenizer = null;
    private String nextHolder = null;

    QuickScanner() {
      bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    }

    QuickScanner(String fileName) {
      try {
        bufferedReader = new BufferedReader(new FileReader(fileName));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }

    boolean hasNext() {
      // Try to get next and put it into nextHolder.
      if (nextHolder == null) {
        nextHolder = next();
      }
      return nextHolder != null;
    }

    String next() {
      // If called hasNext before, should return string in nextHolder.
      if (nextHolder != null) {
        String next = nextHolder;
        nextHolder = null;
        return next;
      }

      try {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
          String newLine = bufferedReader.readLine();
          if (newLine != null) {
            stringTokenizer = new StringTokenizer(newLine);
          } else {
            return null;
          }
        }
        return stringTokenizer.nextToken();
      } catch (IOException e) {
        e.printStackTrace();
        return null;
      }
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    BigInteger nextBigInteger() {
      return new BigInteger(next());
    }

    BigDecimal nextBigDecimal() {
      return new BigDecimal(next());
    }
  }

  private static class MathUtils {

    private static final BigInteger BIG_ZERO = new BigInteger("0");
    private static final BigInteger BIG_ONE = new BigInteger("1");
    private static final BigInteger BIG_TWO = new BigInteger("2");
    private static final SecureRandom RANDOM = new SecureRandom();

    static boolean isProbablePrime(long x) {
      return BigInteger.valueOf(x).isProbablePrime(30);
    }

    static long multiplyMod(long a, long b, long c) {
      a %= c;
      b %= c;
      long ret = 0;
      while (b > 0) {
        if ((b & 1) == 1) {
          ret += a;
          if (ret >= c) {
            ret -= c;
          }
        }
        a <<= 1;
        if (a >= c) {
          a -= c;
        }
        b >>= 1;
      }
      return ret;
    }


    static long modPow(long x, long n, long mod) {
      long ret = 1;
      while (n > 0) {
        if ((n & 1) == 1) {
          ret = multiplyMod(ret, x, mod);
        }
        x = multiplyMod(x, x, mod);
        n >>= 1;
      }
      return ret;
    }

    static long reverseRoot(long x, long prime) {
      assertTrue(isProbablePrime(prime));
      return modPow(x, prime - 2, prime);
    }

    static BigInteger rho(BigInteger N) {
      BigInteger divisor = null;
      BigInteger c = new BigInteger(N.bitLength(), RANDOM);
      BigInteger x = new BigInteger(N.bitLength(), RANDOM);
      BigInteger xx = x;

      // check divisibility by 2
      if (N.mod(BIG_TWO).compareTo(BIG_ZERO) == 0) {
        return BIG_TWO;
      }

      do {
        x = x.multiply(x).mod(N).add(c).mod(N);
        xx = xx.multiply(xx).mod(N).add(c).mod(N);
        xx = xx.multiply(xx).mod(N).add(c).mod(N);
        divisor = x.subtract(xx).gcd(N);
      } while ((divisor.compareTo(BIG_ONE)) == 0);

      return divisor;
    }

    static void factorWorker(BigInteger N, List<BigInteger> result) {
      if (N.compareTo(BIG_ONE) == 0) {
        return;
      }
      if (N.isProbablePrime(30)) {
        result.add(N);
        return;
      }
      BigInteger divisor = rho(N);
      factorWorker(divisor, result);
      factorWorker(N.divide(divisor), result);
    }

    static List<BigInteger> factor(BigInteger N) {
      List<BigInteger> result = new ArrayList<BigInteger>();
      factorWorker(N, result);
      Collections.sort(result);
      return result;
    }
  }

  /**
   * A class to handle range coloring problem.
   *
   */
  private class Intervals {
    private TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();

    Intervals() {
      this(-1);
    }

    /**
     * Color range (-inf, inf) to default color.
     * 
     * @param defaultColor the default color in int.
     */
    Intervals(int defaultColor) {
      map.put(Integer.MIN_VALUE, defaultColor);
      map.put(Integer.MAX_VALUE, defaultColor);
    }


    /**
     * Color range [left, right) to color. The cost is O(logN).
     * 
     * @param left the left border of the range, inclusive.
     * @param right the right border of the range, exclusive.
     * @param color the new color of the range.
     */
    void paintColor(int left, int right, int color) {
      int prevColor = getColor(right);
      map.subMap(left, right).clear();
      map.put(left, color);
      map.put(right, prevColor);
    }


    /**
     * Return current color by index.
     * 
     * @param index the index to query.
     * @return the color of position index.
     */
    int getColor(int index) {
      return map.floorEntry(index).getValue();
    }

    /**
     * Return the map for some future operation.
     * 
     * @return the map itself.
     */
    TreeMap<Integer, Integer> getMap() {
      return map;
    }
  }

  /**
   * A class to solve Range Minimum/Maximum Query problem.
   *
   */
  private class RMQ {

    private int[] data;
    private int[][] table;
    private final Comparator<Integer> comparator;

    /**
     * Build Sparse Table with comparator.
     * 
     * @param data the origin data.
     * @param comparator how to compare the data.
     */
    RMQ(int[] data, Comparator<Integer> comparator) {
      int n = data.length;
      int m = log2(n) + 1;
      this.data = data;
      this.comparator = comparator;
      table = new int[m][n];
      for (int i = 0; i < n; i++) {
        table[0][i] = i;
      }
      for (int i = 1, k = 1; i < m; i++, k <<= 1) {
        for (int j = 0; j + k < n; j++) {
          if (comparator.compare(data[table[i - 1][j]], data[table[i - 1][j + k]]) <= 0) {
            table[i][j] = table[i - 1][j];
          } else {
            table[i][j] = table[i - 1][j + k];
          }
        }
      }
    }

    /**
     * Query and return the index of the "smallest" number defined by comparator in range[from, to)
     * 
     * @param from the left border of the range, inclusive.
     * @param to the right border of the range, exclusive.
     * @return the index of the "smallest" number.
     */
    int query(int from, int to) {
      int k = log2(to - from);
      if (comparator.compare(data[table[k][from]], data[table[k][to - (1 << k)]]) <= 0) {
        return table[k][from];
      } else {
        return table[k][to - (1 << k)];
      }
    }

    private int log2(int b) {
      return 31 - Integer.numberOfLeadingZeros(b);
    }
  }

  // Tedious code.
  public Main() {}

  @Override
  public void run() {
    QuickScanner in = new QuickScanner();
    PrintWriter out = new PrintWriter(System.out);
    try {
      solve(in, out);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      out.flush();
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }

}