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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
 
 
public class Solution{
    
    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;
        
        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }
        
        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }
        
        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }
        
        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
      
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }
        
        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }
            
        }
        public String readLine() throws IOException{
            return s.readLine();
        }
        
        public void close() throws IOException{
            s.close();
        }
        
    }
    
    ////////////////////////////////////////////////////////////////////
    //      Number Theory
    
    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;         
        }
        return x;
    }
    
    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;
 
        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }
    
    void findSubsets(int array[]){
        long numOfSubsets = 1 << array.length; 
        for(int i = 0; i < numOfSubsets; i++){    
            int pos = array.length - 1;
            int bitmask = i;
            while(bitmask > 0){     
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");
                bitmask >>= 1;
                pos--;
            }
            ww.println();
        }
    }
    
    
    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }
    
  
    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }
    
    public static int lcm(int a, int b){
        return (int) (a*b/gcd(a,b));
    }
    
    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }
    
    ////////////////////////////////////////////////////////////////////
    
    
//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream); 
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };
    
      
    //////////////////////////////////////////////////////////////////// 
      
     
    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }
    
    
    ////////////////////////////////////////////////////////////////////
    
    class Node implements Comparable<Node>{
        int x;
        int y;
        public Node(int x,int y){
            this.x = x;
            this.y = y;
        }
        @Override
        public int compareTo(Node arg0) {
            // TODO Auto-generated method stub
            return Integer.compare(y, arg0.y);
        }
    }
    
    void solve() throws IOException{
        
        int n = s.nextInt();
        int m = s.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        int sum = 0;
        Set<Integer> st = new HashSet<Integer>();
        for(int i=0;i<n;i++){
            a[i] = s.nextInt();
            sum += a[i];
        }
        
        for(int i=0;i<m;i++){
            int xx = s.nextInt()-1;
            b[i] = xx;
            st.add(xx);
        }
        
        Node[] sort = new Node[st.size()];
        Set<Integer> mk = new HashSet<Integer>();
        int cnt = 0;
 //     for(int ml : b) ww.println(ml);
        
        for(int i=0;i<m;i++){
            Set<Integer> mm = new HashSet<Integer>();
            int get = 0;
            int gum = 0;
            int xx = b[i];
            if(mk.contains(xx)) continue;
            mk.add(xx);
            get += (sum-a[xx]);
            for(int j=i+1;j<m;j++){
                if(b[j] == xx){
                    mm = new HashSet<Integer>();
                    get += gum;
                    gum = 0;
                }
                else if(!mm.contains(b[j])){
                    gum += a[b[j]];
                    mm.add(b[j]);
                }
            }
 //         ww.println(get);
            sort[cnt++] = new Node(xx,get);
        }
        
        Arrays.sort(sort,0,cnt,Collections.reverseOrder());
        int[] index = new int[10000];
        int[] dp = new int[cnt];
        
        for(int i=0;i<cnt;i++){
            if(i == 0) dp[i] = a[sort[i].x];
            else dp[i] = a[sort[i].x]+dp[i-1];
            index[sort[i].x] = i;
        }
        
//      ww.println(index[2]+" "+index[1]+" "+index[0]);
        int get = 0;
        mk = new HashSet<Integer>();
        
        for(int i=0;i<m;i++){
            Set<Integer> mm = new HashSet<Integer>();
            int gum = 0;
            int xx = b[i];
            if(mk.contains(xx)) continue;
            mk.add(xx);
            get += dp[index[xx]]-a[xx];
            for(int j=i+1;j<m;j++){
                if(b[j] == xx){
                    mm = new HashSet<Integer>();
                    get += gum;
                    gum = 0;
                }
                else if(!mm.contains(b[j])){
                    gum += a[b[j]];
                    mm.add(b[j]);
                }
            }
        }
        
        ww.println(get);
        
    }
}


