public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        int n = Reader.nextInt();
        int k = Reader.nextInt();
        
        int[] a = new int[n+1];
        int[] pos = new int[n+1];
        for (int i = 0; i < n; i++) {
            int x = Reader.nextInt();
            a[i+1] = x;
            pos[x] = i + 1;
        }
        
        int[] remain = new int[k];
        for (int i = 0; i < k; i++) {
            remain[i] = Reader.nextInt();
        }
        
        HashSet<Integer> togo = new HashSet<Integer>();
        int cur = 1;
        for (int i = 0; i < k; i++) {
            while (a[cur] != remain[i]) {
                togo.add(a[cur]);
                cur++;
            }
            cur++;
        }
        for (; cur < n+1; cur++) {
            togo.add(a[cur]);
        }
        
        BIT bit = new BIT(n);
        TreeSet<Integer> occu = new TreeSet<Integer>();
        long result = 0;
        for (int i = 1; i < n+1; i++) {
            int x = pos[i];
            if (togo.contains(i)) {
                int right = (occu.ceiling(x+1) == null ? n : occu.ceiling(x+1)-1);
                int left  = (occu.floor(x-1) == null ? 1 : occu.floor(x-1)+1);
                int discarded = getDiscarded(bit, left, right);
                result += right - left + 1 - discarded;
                bit.set(x, 1);
            } else {
                occu.add(x);
            }
        }
        
        System.out.println(result);
    }