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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author L_aka_ryuga
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CLoseIt solver = new CLoseIt();
        solver.solve(1, in, out);
        out.close();
    }

    static class CLoseIt {
        public void solve(int testNumber, InputReader in, OutputWriter out) {

            int[] check = {0, 4, 8, 15, 16, 23, 42};
            int n = in.ni();
            int[] arr = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                arr[i] = in.ni();
            }

            int[][] ans = new int[check.length][n + 1];

            for (int i = 0; i < n + 1; i++) ans[0][i] = Integer.MAX_VALUE;

            for (int i = 1; i < check.length; ++i) {
                for (int j = 1; j <= n; j++) {

                    if (check[i] == arr[j]) {
                        ans[i][j] = Math.min(ans[i][j - 1] + 1, ans[i - 1][j]);
                    } else
                        ans[i][j] = ans[i][j - 1];

                }
            }

        /*for(int i = 0;i < check.length + 1 ; i++){
            for(int j = 0;j < n + 1;j++) out.print(ans[i][j]+" ");
            out.println();
        }*/
            out.println(n - 6 * ans[check.length - 1][n]);


        /*
        int[] count = new int[43];
        _Ez_Int_ArrayList[] list = new _Ez_Int_ArrayList[6];
        for(int i = 0; i < 6;i++)list[i] = new _Ez_Int_ArrayList();

        for(int i = 0;i < arr.length ;i++){
            count[arr[i]]++;
            list[getIndex(check , arr[i])].add(i);
        }

        int min = Integer.MAX_VALUE;

        for(int i = 0;i < check.length;i++){
            min = Math.min(min , count[check[i]]);
        }


        int remove = 0;
        int[] get4 = {0 , -1};
        int[] get8 = {0 , -1};
        int[] get15 = {0 , -1};
        int[] get16 = {0 , -1};
        int[] get23 = {0 , -1};
        int[] get42 = {0 , -1};

        for(int i = 0;i < min ; i++){
            get4[0] = list[0].get(i);
            get8 = getNextGreater(list[1] , get4[0] , get8[1]);
            get15 = getNextGreater(list[2] , get8[0] , get15[1]);
            get16 = getNextGreater(list[3] , get15[0] , get16[1]);
            get23 = getNextGreater(list[4] , get16[0] , get23[1]);
            get42 = getNextGreater(list[5] , get23[0] , get42[1]);

            if(get4[0] < get8[0] && get8[0] < get15[0] && get15[0] < get16[0] && get16[0] < get23[0] && get23[0] < get42[0]){
                remove += 6;

            }
            else break;
        }

        out.println(n - remove);
        */

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

