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.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
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 = {4, 8, 15, 16, 23, 42};
            int n = in.ni();
            int[] arr = in.nia(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]]);
            }

            /*for(int i = 0;i < 6;i++) out.println(list[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);

        }

        private int[] getNextGreater(_Ez_Int_ArrayList ez_int_arrayList, int ele, int i) {
            int[] ans = {-1, 0};
            int index = i + 1;
            while (!ez_int_arrayList.isEmpty() && index < ez_int_arrayList.size()) {
                if (ez_int_arrayList.get(index) > ele) {
                    ans[0] = ez_int_arrayList.get(index);
                    ans[1] = index;
                    break;
                }
                index++;
            }

            return ans;
        }

        private int getIndex(int[] check, int ele) {
            int ret = 0;
            for (int i = 1; i < check.length; i++) {
                if (check[i] == ele) return i;
            }
            return ret;
        }

    }

    static interface _Ez_Int_Iterator {
        boolean hasNext();

        int next();

    }

    static interface _Ez_Int_Collection {
        int size();

        _Ez_Int_Iterator iterator();

        boolean equals(Object object);

        int hashCode();

        String toString();

    }

    static interface _Ez_Int_Stack extends _Ez_Int_Collection {
        int size();

        _Ez_Int_Iterator iterator();

        boolean equals(Object object);

        int hashCode();

        String toString();

    }

    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 int[] nia(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = ni();
            return array;
        }

        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);
        }

    }

    static class _Ez_Int_ArrayList implements _Ez_Int_List, _Ez_Int_Stack {
        private static final int DEFAULT_CAPACITY = 10;
        private static final double ENLARGE_SCALE = 2.0;
        private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;
        private static final int HASHCODE_MULTIPLIER = 0x01000193;
        private int/*T*/[] array;
        private int size;

        public _Ez_Int_ArrayList() {
            this(DEFAULT_CAPACITY);
        }

        public _Ez_Int_ArrayList(int capacity) {
            if (capacity < 0) {
                throw new IllegalArgumentException("Capacity must be non-negative");
            }
            array = new /*T*/int/*T*/[capacity];
            size = 0;
        }

        public _Ez_Int_ArrayList(_Ez_Int_Collection collection) {
            size = collection.size();
            array = new /*T*/int/*T*/[size];
            int i = 0;
            for (_Ez_Int_Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
                array[i++] = iterator.next();
            }
        }

        public _Ez_Int_ArrayList(/*T*/int/*T*/[] srcArray) {
            size = srcArray.length;
            array = new /*T*/int/*T*/[size];
            System.arraycopy(srcArray, 0, array, 0, size);
        }

        public _Ez_Int_ArrayList(Collection</*W*/Integer/*W*/> javaCollection) {
            size = javaCollection.size();
            array = new /*T*/int/*T*/[size];
            int i = 0;
            for (/*T*/int/*T*/ element : javaCollection) {
                array[i++] = element;
            }
        }

        public int size() {
            return size;
        }

        public boolean isEmpty() {
            return size == 0;
        }

        public _Ez_Int_Iterator iterator() {
            return new _Ez_Int_ArrayListIterator();
        }

        public boolean add(/*T*/int/*T*/ element) {
            if (size == array.length) {
                enlarge();
            }
            array[size++] = element;
            return true;
        }

        public int get(int index) {
            if (index < 0 || index >= size) {
                throw new IndexOutOfBoundsException("Index " + index + " is out of range, size = " + size);
            }
            return array[index];
        }

        private void enlarge() {
            int newSize = Math.max(size + 1, (int) (size * ENLARGE_SCALE));
            /*T*/
            int/*T*/[] newArray = new /*T*/int/*T*/[newSize];
            System.arraycopy(array, 0, newArray, 0, size);
            array = newArray;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            _Ez_Int_ArrayList that = (_Ez_Int_ArrayList) o;

            if (size != that.size) {
                return false;
            }
            for (int i = 0; i < size; i++) {
                if (array[i] != that.array[i]) {
                    return false;
                }
            }
            return true;
        }

        public int hashCode() {
            int hash = HASHCODE_INITIAL_VALUE;
            for (int i = 0; i < size; i++) {
                hash = (hash ^ PrimitiveHashCalculator.getHash(array[i])) * HASHCODE_MULTIPLIER;
            }
            return hash;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append('[');
            for (int i = 0; i < size; i++) {
                sb.append(array[i]);
                if (i < size - 1) {
                    sb.append(", ");
                }
            }
            sb.append(']');
            return sb.toString();
        }

        private class _Ez_Int_ArrayListIterator implements _Ez_Int_Iterator {
            private int curIndex = 0;

            public boolean hasNext() {
                return curIndex < size;
            }

            public int next() {
                if (curIndex == size) {
                    throw new NoSuchElementException("Iterator doesn't have more elements");
                }
                return array[curIndex++];
            }

        }

    }

    static interface _Ez_Int_List extends _Ez_Int_Collection {
        int size();

        _Ez_Int_Iterator iterator();

        boolean equals(Object object);

        int hashCode();

        String toString();

    }

    static final class PrimitiveHashCalculator {
        private PrimitiveHashCalculator() {
        }

        public static int getHash(int x) {
            return x;
        }

    }
}

