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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Stream;

/**
 * <pre>
 * You've got a way to keep me on your side. You give me cause for love that I can't hide.
 * For you I know I'd even try to turn the tide. Because you're mine, I walk the line.
 * </pre>
 * @author bodmas
 * @since Jun 9, 2019.
 */
public class ProblemC {

    private static final int[] x = {4, 8, 15, 16, 23, 42};

    private int goodLength(int[] a) {
        if (a.length < 6)
            return a.length;
        int toRemove = a.length;
        Integer[] pos = new Integer[a.length];
        for (int i = 0; i < pos.length; i++)
            pos[i] = i;
        Arrays.sort(pos, (i, j) -> a[i] == a[j] ? i - j : a[i] - a[j]);
        int[] indices = new int[x.length];

        for (int i = 0; i < x.length; i++) {
            int left = -1;
            int right = a.length - 1;
            while (right - left > 1) {
                int mid = left + right >> 1;
                if (a[pos[mid]] < x[i])
                    left = mid;
                else
                    right = mid;
            }
            if (a[pos[right]] != x[i])
                return a.length;
            indices[i] = right;
        }

        boolean initialCycle = true;
        while (true) {
            for (int i = 1; i < x.length; i++) {
                while (pos[indices[i]] < pos[indices[i - 1]] && ++indices[i] != pos.length && a[pos[indices[i]]] == a[pos[indices[i] - 1]]);
                if (indices[i] == pos.length || (!initialCycle && a[pos[indices[i]]] != a[pos[indices[i] - 1]]))
                    return toRemove;
            }
            toRemove -= x.length;
            for (int i = 0; i < x.length; i++)
                if (++indices[i] == pos.length || a[pos[indices[i]]] != a[pos[indices[i] - 1]])
                    return toRemove;
            initialCycle = false;
        }
    }

    private int solve(int[] a) {
        return goodLength(a);
    }

    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            readLine(in);
            int[] a = Stream.of(readLine(in).split(" ")).mapToInt(Integer::parseInt).toArray();
            out.println(new ProblemC().solve(a));
        }
    }

    private static String readLine(BufferedReader in) {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
