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.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
 public static void main(String[] args) throws Exception {
        //Scanner in = new Scanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
       BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        InputReader in=new InputReader(System.in);
        
        int n=in.nextInt();
        int freq[]=new int[6];
        freq[0]=4;
        freq[1]=8;
        freq[2]=15;
        freq[3]=16;
        freq[4]=23;
        freq[5]=42;

        int[] arr=new int[n];
        Queue<Integer> ind[]=new Queue[6];
        for(int i=0;i<6;i++)ind[i]=new LinkedList<>();
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
            if(arr[i]==4)ind[0].add(i);
            if(arr[i]==8)ind[1].add(i);
            if(arr[i]==15)ind[2].add(i);
            if(arr[i]==16)ind[3].add(i);
            if(arr[i]==23)ind[4].add(i);
            if(arr[i]==42)ind[5].add(i);
        }

        int cnt=0;
        for(int i=0;i<n;i++){
            int index=0;
            ArrayList<Integer> temp=new ArrayList<>();
            if(ind[0].isEmpty())break;
            index=ind[0].poll();
            temp.add(index);

            for(int j=1;j<6;j++){
                
                while(temp.size()>0 && !ind[j].isEmpty() && temp.get(temp.size()-1)>ind[j].peek()){
                    ind[j].poll();
                }
                if(!ind[j].isEmpty())temp.add(ind[j].poll());
            

                // for(int k=index+1;k<n;k++){
                //     if(arr[k]==freq[j]){
                //         //arr[k]=-freq[j];
                //         index=k;
                //         temp.add(k);
                //         break;
                //     }
                // }
            }
            if(temp.size()==6){
                for(int j=0;j<temp.size();j++)arr[temp.get(j)]=-1;


            }else break;
        }
       // int cnt=0;
        for(int i=0;i<n;i++){
            //System.out.print(arr[i]+" ");
            if(arr[i]>0)cnt++;
        }
        System.out.println(cnt);









        // Queue<Integer> q[]=new Queue[6];
        // for(int i=0;i<6;i++){
        //     q[i]=new LinkedList<>();
        // }
        // for(int i=0;i<n;i++){
        //     int te=in.nextInt();
        //     if(te==4)q[0].add(i);
        //     if(te==8)q[1].add(i);
        //     if(te==15)q[2].add(i);
        //     if(te==16)q[3].add(i);
        //     if(te==23)q[4].add(i);  
        //     if(te==42)q[5].add(i);
        // }
        // int cnt=0;
        // int f=0;
        
        // while(!q[0].isEmpty()){
        //     System.out.println(q[0].peek()+" "+q[5].peek());
        //     while(!q[5].isEmpty() && !q[0].isEmpty() && q[0].peek()>q[5].peek()){
                
        //         q[0].poll();

        //         cnt++;
        //     }
        //     // if(q[5].isEmpty() || q[0].isEmpty()){
        //     //     f=1;
        //     //     System.out.println(f);
        //     //     break;
        //     // } 
        //     for(int i=1;i<6;i++){
        //         while(!q[i].isEmpty() && q[i].peek()<q[i-1].peek()){
        //             q[i].poll();
        //             cnt++;
        //         }
        //         if(q[i].isEmpty()){
        //             f=1;
        //             break;
        //         }
        //     }
        //     if(f==1){
        //         break;
        //     }
        //     for(int i=0;i<6;i++){
        //         q[i].poll();
        //     }
        // }
        
        // if(f==1){
        //     System.out.println(n);
            
        // }else System.out.println(cnt);
                
    
        
        pw.flush();
        pw.close();
        
   }
   static class Pair implements Comparable<Pair>{
        int x;
        int y;
        Pair(int a,int b){
            x=a;
            y=b;
        }
        @Override
        public int compareTo(Pair t){
            if(x>t.x)return 1;
            else if(x==t.x){
                if(y>=t.y)return 1;
                else return -1;
            }
            else return -1;
        }
        @Override
        public boolean equals(Object obj){
            if(this==obj)return true;
            Pair that=(Pair)obj;
            if(this.x==that.x && this.y==that.y)return true;
            return false;
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

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

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

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

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

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public long[] nextLongArray(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
                
        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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