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.*;

public class R564B {
	static HashMap<Integer,Integer> map = new HashMap<>();
	static boolean[] v;
	static int idx5;
	public static void main(String[] args) {
		JS scan = new JS();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int[] arr =new int[n];
		for(int i = 0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		map = new HashMap<Integer,Integer>();
		int start = 0;
		for(int i = 0;i<n;i++){
			if(arr[i]==4){
				start = i;
				break;
			}
		}
		for(int i = 0;i<n;i++){
			if(!map.containsKey(arr[i]))
			map.put(arr[i], i-1);
		}
		v = new boolean[n];
		int ans = 0;
		for(int i = 0;i<n;i++){
			if(arr[i]==4)go(i,arr);
			
		}
		for(int i = 0;i<n;i++){
			if(!v[i])ans++;
		}
		System.out.println(ans);
		
	}
	public static boolean go(int idx, int[] arr){
		idx5 = idx;
		if(arr[idx]==4){
			if(map.get(8)==null){
				v[idx] = false;
				return false;
			}
			int next = map.get(8);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			boolean pass = false;
			for(int i = Math.max(next+1,idx+1);i<arr.length;i++){
				if(arr[i]==8){
					pass = true;
					map.put(arr[i], i);
					next = i;

					break;
				}
			}
			if(!pass)next = 9999999;
			map.put(8,next);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			return v[idx] = go(next,arr);
		}
		if(arr[idx]==8){
			if(map.get(15)==null){
				v[idx] = false;
				return false;
			}
			int next = map.get(15);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			boolean pass = false;
			for(int i = Math.max(next+1,idx+1);i<arr.length;i++){
				if(arr[i]==15){
					pass = true;
					map.put(arr[i], i);
					next = i;

					break;
				}
			}
			if(!pass)next = 9999999;
			map.put(15,next);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			return v[idx] = go(next,arr);
		}
		if(arr[idx]==15){
			if(map.get(16)==null){
				v[idx] = false;
				return false;
			}
			int next = map.get(16);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			boolean pass = false;
			for(int i = Math.max(next+1,idx+1);i<arr.length;i++){
				if(arr[i]==16){
					pass = true;
					map.put(arr[i], i);
					next = i;

					break;
				}
			}
			if(!pass)next = 9999999;
			map.put(16,next);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			return v[idx] = go(next,arr);
		}
		if(arr[idx]==16){
			if(map.get(23)==null){
				v[idx] = false;
				return false;
			}
			int next = map.get(23);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			boolean pass = false;
			for(int i = Math.max(next+1,idx+1);i<arr.length;i++){
				if(arr[i]==23){
					pass = true;
					map.put(arr[i], i);
					next = i;
					break;
				}
			}
			if(!pass)next = 9999999;
			map.put(23,next);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			return v[idx] = go(next,arr);
		}
		if(arr[idx]==23){
			if(map.get(42)==null){
				v[idx] = false;
				return false;
			}
			int next = map.get(42);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			boolean pass = false;
			for(int i = Math.max(next+1,idx+1);i<arr.length;i++){
				if(arr[i]==42){
					pass = true;
					map.put(arr[i], i);
					next = i;

					break;
				}
			}
			if(!pass)next = 9999999;
			map.put(42,next);
			if(next>=arr.length){
				v[idx] = false;
				return false;
			}
			return v[idx] = go(next,arr);
		}
		if(arr[idx]==42){
			v[idx] = true;
			return true;
		}
		return false;
	}
	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}				
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}

}
