You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.

Your task is to remove the minimum number of elements to make this array good.

An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42.

Examples of good arrays:

  * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); 
  * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); 
  * [] (the empty array is good). 



Examples of bad arrays: 

  * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); 
  * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); 
  * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). 

Input

The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a.

The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a.

Output

Print one integer — the minimum number of elements you have to remove to obtain a good array.

Examples

Input


5
4 8 15 16 23


Output


5


Input


12
4 8 4 15 16 8 23 15 16 42 23 42


Output


0


Input


15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42


Output


3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class CF1176_D2_C {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        int[] arr = scanner.nextArray(n);
        // 4 8 15 16 23 42
        ArrayList<Integer> a4 = new ArrayList<>();
        ArrayList<Integer> a8 = new ArrayList<>();
        ArrayList<Integer> a15 = new ArrayList<>();
        ArrayList<Integer> a16 = new ArrayList<>();
        ArrayList<Integer> a23 = new ArrayList<>();
        ArrayList<Integer> a42 = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            switch (arr[i]) {
                case 4:
                    a4.add(i);
                    break;
                case 8:
                    a8.add(i);
                    break;
                case 15:
                    a15.add(i);
                    break;
                case 16:
                    a16.add(i);
                    break;
                case 23:
                    a23.add(i);
                    break;
                case 42:
                    a42.add(i);
                    break;
            }
        }
        int count = 0;
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
        int index = -1;
        for (; a < a4.size(); a++) {
            index = a4.get(a);
            for (; b < a8.size(); b++) {
                if (a8.get(b) > index) {
                    index = a8.get(b++);
                    break;
                }
            }
            if(arr[index] != 8){
                break;
            }
            for (; c < a15.size(); c++) {
                if (a15.get(c) > index) {
                    index = a15.get(c++);
                    break;
                }
            }
            if(arr[index] != 15){
                break;
            }
            for (; d < a16.size(); d++) {
                if (a16.get(d) > index) {
                    index = a16.get(d++);
                    break;
                }
            }
            if(arr[index] != 16){
                break;
            }
            for (; e < a23.size(); e++) {
                if (a23.get(e) > index) {
                    index = a23.get(e++);
                    break;
                }
            }
            if(arr[index] != 23){
                break;
            }
            for (; f < a42.size(); f++) {
                if (a42.get(f) > index) {
                    index = a42.get(f++);
                    break;
                }
            }
            if (arr[index] == 42) {
                count++;
            } else {
                break;
            }
        }

        System.out.println(n - count * 6);


//        HashMap<Integer, Integer> map = new HashMap<>();
//        map.put(4, 0);
//        map.put(8, 0);
//        map.put(15, 0);
//        map.put(16, 0);
//        map.put(23, 0);
//        map.put(42, 0);
//        for (int i = 0; i < n; i++) {
//            map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
//        }
//        int min = Integer.MAX_VALUE;
//        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
//            min = Math.min(e.getValue(), min);
//        }
//        int count = 0;
//
//        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
//            count += (e.getValue() - min);
//        }
//        System.out.println(count);

    }

    static int greaterSearch(ArrayList<Integer> arr, int target) {
        int start = 0, end = arr.size() - 1;
        int ans = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (arr.get(mid) <= target) {
                start = mid + 1;
            } else {
                ans = mid;
                end = mid - 1;
            }
        }
        return ans;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}