/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
//#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    int aaa[43];
    memset(aaa, 0, sizeof(aaa));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=aaa[8];v[8].size()>j;j++)
        {
            if(v[8][j]<v[4][i] || mark[v[8][j]])
            {
                aaa[8]=j;
                continue;
            }
            for(int k=aaa[15];v[15].size()>k;k++)
            {
                if(v[15][k]<v[8][j]||mark[v[15][k]])
                {
                    aaa[15]=k;
                    continue;
                }
                for(int l=aaa[16];v[16].size()>l;l++)
                {
                    if(v[16][l]<v[15][k]||mark[v[16][l]])
                    {
                        aaa[16]=l;
                        continue;
                    }
                    for(int m=aaa[23];v[23].size()>m;m++)
                    {
                        if(v[23][m]<v[16][l]||mark[v[23][m]])
                        {
                            aaa[23]=m;
                            continue;
                        }
                        for(int z=aaa[42];v[42].size()>z;z++)
                        {
                            if(v[42][z]<v[23][m]||mark[v[42][z]])
                            {
                                aaa[42]=z;
                                continue;
                            }
                            else
                            {
                                ans++;
                                mark[v[4][i]]=mark[v[8][j]]=mark[v[15][k]]=mark[v[16][l]]=mark[v[23][m]]=mark[v[42][z]]=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}


/*  C++ Template for Competetive Coding
 $ All functions in template has suffix "Function"
 $ Sieve,Factorial,BinaryExpo,ModInverse
 $ FASTIO !!

 -Anuj Mittal
 unusual_wonder
 */
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int a,int n)//binary exponentation
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=powerFunction(a,n/2);
    if(n%2==0)
        return ((r)%MOD)*((r)%MOD)%MOD;
    else
        return ((r)%MOD)*((r)%MOD)*((a)%MOD)%MOD;
}
int modInverseFunctionFunction(int no) {
    int inverse=1;
    while(P>0){
        if(P&1){
            inverse=(inverse%MOD*no%MOD)%MOD;
        }
        no=(no%MOD*no%MOD)%MOD;
        P=P/2;
    }
    P=MOD-2;
    return inverse%MOD;
}
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for(int i=2;maxLimit>=i;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;maxLimit>j;j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit)
{
    factorial[0]=1;
    for(int i=1;i<=maxLimit;i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int GCD(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    // base case
    if (a == b)
        return a;
    // a is greater
    if (a > b)
        return GCD(a%b, b);
    return GCD(a, b%a);
}

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<int> v[43];
    for(int i=0;n>i;i++)
    {
        cin>>arr[i];
        v[arr[i]].push_back(i);
    }
    int ans=0;
    int mark[n];
    memset(mark, 0, sizeof(mark));
    for(int i=0;v[4].size()>i;i++)
    {
        for(int j=0;v[8].size()>j;j++)
        {
            if(j<i || mark[j])
                continue;
            for(int k=0;v[15].size()>k;k++)
            {
                if(k<j||mark[k])
                    continue;
                for(int l=0;v[16].size()>l;l++)
                {
                    if(l<k||mark[l])
                        continue;
                    for(int m=0;v[23].size()>m;m++)
                    {
                        if(m<l||mark[m])
                            continue;
                        for(int z=0;v[42].size()>z;z++)
                        {
                            if(z<m||mark[z])
                                continue;
                            else
                            {
                                ans++;
                                mark[i]=mark[j]=mark[k]=mark[l]=mark[m]=mark[z]=1;
                                goto l;
                            }

                        }
                    }
                }
            }
        }
    l:
        continue;
    }
    cout<<n-ans*6<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, f[100];
int ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &x);
    if (x == 8) f[4]--;
    else if (x==15) f[8]--;
    else if (x==16) f[15]--;
    else if (x==23) f[16]--;
    else if (x==42) f[23]--, ans++;
    f[x]++;
  }
  printf("%d\n", n - ans * 6);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, f[100];
int ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &x);
    if (x == 8) f[4] = max(0, f[4]-1);
    else if (x==15) f[8] = max(0, f[8]-1);
    else if (x==16) f[15] = max(0, f[15]-1);
    else if (x==23) f[16] = max(0, f[16]-1);
    else if (x==42) {
      if (f[23]) {
        f[23]--;
        ans++;
      }
    }
    f[x]++;
  }
  printf("%d\n", n - ans * 6);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt;
ll ans;
set<int>s[56];
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &x);
    if (x==4) s[0].insert(i);
    else if (x==8) s[1].insert(i);
    else if (x==15) s[2].insert(i);
    else if (x==16) s[3].insert(i);
    else if (x==23) s[4].insert(i);
    else s[5].insert(i);
  }
  while (true) {
    if (s[0].empty()) break;
    int pos = *s[0].begin();
    s[0].erase(s[0].begin());
    FOR(i,1,5) {
      auto it = s[i].lower_bound(pos);
      if (it == s[i].end()) {
        goto there;
      }
      pos = *it;
      s[i].erase(it);
    }
    ans++;
  }
  there:;
  printf("%d\n", n - ans * 6);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, f[100];
int ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &x);
    if (x == 4) {
      f[4]++;
    }
    else if (x == 8) {
      if (f[4]) {
        f[4]--;
        f[8]++;
      }
    }
    else if (x==15) {
      if (f[8]) {
        f[8]--;
        f[15]++;
      }
    }
    else if (x==16) {
      if (f[15]) {
        f[15]--;
        f[16]++;
      }
    }
    else if (x==23) {
      if (f[16]) {
        f[16]--;
        f[23]++;
      }
    }
    else if (x==42) {
      if (f[23]) {
        f[23]--;
        f[42]++;
      }
    }
  }
  printf("%d\n", n - f[42] * 6);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, f[100];
int ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &x);
    if (x == 8) {
      if (f[4]) {
        f[4]--;
        f[8]++;
      }
    }
    else if (x==15) {
      if (f[8]) {
        f[8]--;
        f[15]++;
      }
    }
    else if (x==16) {
      if (f[15]) {
        f[15]--;
        f[16]++;
      }
    }
    else if (x==23) {
      if (f[16]) {
        f[16]--;
        f[23]++;
      }
    }
    else if (x==42) {
      if (f[23]) {
        f[23]--;
        f[42]++;
      }
    }
  }
  printf("%d\n", n - f[42] * 6);
  return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
//ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//LL gcd(LL a,LL b){
//return b==0 ? a:gcd(b,a%b);
//}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int sum_of_digit(long long n)
{
    if (n == 0)
    return 0;
    return (n % 10 + sum_of_digit(n / 10));
}

long long MOD = 1000000007;
long long f(long long n){
    if(n==1){
        return 2;
    }
    long long x=f(n/2);
    if(n%2){

        return ((x*x)%MOD)*2%MOD;
    }else{
        return ((x*x)%MOD);
    }
}
float power(float x, int y)
{
    float temp;
    if(y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
float squareRoot(float n)
    {

        float x = n;
        float y = 1;
        float e = 0.000001; /* e decides the accuracy level*/
        while (x - y > e) {
            x = (x + y) / 2;
            y = n / x;
        }
        return x;
    }
const int maxn=100005;
    int ans=0,mat[maxn];
    void fi(int a)
    { for(int i=2;i*i<=a;++i)
     {if(a%i==0)
     mat[i]++;
     while(a%i==0)
        a/=i;}
        if(a>1)

            mat[a]++;

    }

int ceil2(int x)
{
    return(x+3-1)/3;
}
int l[200003];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);

int n,i,x,y,t[6]={0},c[100];

	c[4]=0,c[8]=1,c[15]=2,c[16]=3,c[23]=4,c[42]=5;cin>>n;
	for(i=0;i<n;i++){
		cin>>x;y=c[x];
		if(y==0)
			{t[y]++;}
		else if(t[y-1]>0){
			t[y-1]--,t[y]++;
		}
	}
	cout<<n-t[5]*6;

return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;

int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);
long long n,x,y,t[6],c[99];

	c[4]=0,c[8]=1,c[15]=2,c[16]=3,c[23]=4,c[42]=5;
	cin >>n;
	for(int i = 0;i<n;i++){
		cin>>x;
		y=c[x];
		if(y==0)
            t[y]++;
		if(t[y-1]>0)
            {t[y-1]--;t[y]++;}
	}
	cout<<n-t[5]*6;

return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
//ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//LL gcd(LL a,LL b){
//return b==0 ? a:gcd(b,a%b);
//}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int sum_of_digit(long long n)
{
    if (n == 0)
    return 0;
    return (n % 10 + sum_of_digit(n / 10));
}

long long MOD = 1000000007;
long long f(long long n){
    if(n==1){
        return 2;
    }
    long long x=f(n/2);
    if(n%2){

        return ((x*x)%MOD)*2%MOD;
    }else{
        return ((x*x)%MOD);
    }
}
float power(float x, int y)
{
    float temp;
    if(y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
float squareRoot(float n)
    {

        float x = n;
        float y = 1;
        float e = 0.000001; /* e decides the accuracy level*/
        while (x - y > e) {
            x = (x + y) / 2;
            y = n / x;
        }
        return x;
    }
const int maxn=100005;
    int ans=0,mat[maxn];
    void fi(int a)
    { for(int i=2;i*i<=a;++i)
     {if(a%i==0)
     mat[i]++;
     while(a%i==0)
        a/=i;}
        if(a>1)

            mat[a]++;

    }

int ceil2(int x)
{
    return(x+3-1)/3;
}
int l[200003];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);

int n,i,x,y,t[6]={0},c[100];

	c[4]=0,c[8]=1,c[15]=2,c[16]=3,c[23]=4,c[42]=5;cin>>n;
	for(i=0;i<n;i++){
		cin>>x;y=c[x];
		if(y==0)
			t[y]++;
		if(t[y-1]>0){
			t[y-1]--,t[y]++;
		}
	}
	cout<<n-t[5]*6;

return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
//ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//LL gcd(LL a,LL b){
//return b==0 ? a:gcd(b,a%b);
//}

bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int sum_of_digit(long long n)
{
    if (n == 0)
    return 0;
    return (n % 10 + sum_of_digit(n / 10));
}

long long MOD = 1000000007;
long long f(long long n){
    if(n==1){
        return 2;
    }
    long long x=f(n/2);
    if(n%2){

        return ((x*x)%MOD)*2%MOD;
    }else{
        return ((x*x)%MOD);
    }
}
float power(float x, int y)
{
    float temp;
    if(y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
float squareRoot(float n)
    {

        float x = n;
        float y = 1;
        float e = 0.000001; /* e decides the accuracy level*/
        while (x - y > e) {
            x = (x + y) / 2;
            y = n / x;
        }
        return x;
    }
const int maxn=100005;
    int ans=0,mat[maxn];
    void fi(int a)
    { for(int i=2;i*i<=a;++i)
     {if(a%i==0)
     mat[i]++;
     while(a%i==0)
        a/=i;}
        if(a>1)

            mat[a]++;

    }

int ceil2(int x)
{
    return(x+3-1)/3;
}
int l[200003];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);
int n,x,y,t[6]={0},c[99];

	c[4]=0,c[8]=1,c[15]=2,c[16]=3,c[23]=4,c[42]=5;
	cin >>n;
	for(int i = 0;i<n;i++){
		cin>>x;
		y=c[x];
		if(y==0)
            t[y]++;
		if(t[y-1]>0)
            t[y-1]--,t[y]++;
	}
	cout<<n-t[5]*6;

return 0;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;

	int occ[50]={0};

	unordered_set<int> m;

	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;

	int j=0,counter=0,a,b,c,d,e,f,co=0;
	int fr,ei=0,fit=0,six=0,sev=0,frty=0;
	for(int i=0; i<four.size();i++)
	{
		counter=1;
		a=four[i];

		if(ei<eight.size()){
		while(a>eight[ei])
			ei++;
		b=eight[ei];
		counter++;
		ei++;
		}

		if(fit<fifteen.size()){
		while(b>fifteen[fit])
			fit++;
		c=fifteen[fit];
		fit++;
		counter++;
		}

		if(six<sixteen.size()){
		while(c>sixteen[six])
			six++;
		d=sixteen[six];
		six++;
		counter++;
		}

		if(sev<seventeen.size()){
		while(d>seventeen[sev])
			sev++;
		e=seventeen[sev];
		sev++;
		counter++;
		}

		if(frty<fortytwo.size()){
		while(e>fortytwo[frty])
			frty++;
		f=fortytwo[frty];
		frty++;
		counter++;
		}
		if(counter==6){
			co++;
		}
	}

//	for(int i=0; i<43; i++)
//		s+=occ[i];
	s=n-(co*6);
	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;

	int occ[50]={0};

	unordered_set<int> m;

	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;
	while(i<four.size() && i<eight.size() && i<fifteen.size() && i<sixteen.size() && i<seventeen.size() && i<fortytwo.size())
	{
		if(four[i]<eight[i]<fifteen[i]<sixteen[i]<seventeen[i]<fortytwo[i])
		{
			occ[4]--;occ[8]--;occ[15]--;occ[16]--;occ[23]--;occ[42]--;
		}
		i++;
	}

	for(int i=0; i<43; i++)
		s+=occ[i];

	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;

	int occ[50]={0};

	unordered_set<int> m;

	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;

	int j=0,counter=0,a,b,c,d,e,f,co=0;
	int fr,ei=0,fit=0,six=0,sev=0,frty=0;
	for(int i=0; i<four.size();i++)
	{
		counter=1;
		a=four[i];

		if(ei<eight.size()){
		while(a>eight[ei] && ei<eight.size())
			ei++;
		b=eight[ei];
		counter++;
		ei++;
		}

		if(fit<fifteen.size()){
		while(b>fifteen[fit] && fit<fifteen.size())
			fit++;
		c=fifteen[fit];
		fit++;
		counter++;
		}

		if(six<sixteen.size()){
		while(c>sixteen[six] && six<sixteen.size())
			six++;
		d=sixteen[six];
		six++;
		counter++;
		}

		if(sev<seventeen.size()){
		while(d>seventeen[sev] && sev<seventeen.size())
			sev++;
		e=seventeen[sev];
		sev++;
		counter++;
		}

		if(frty<fortytwo.size()){
		while(e>fortytwo[frty] && frty<fortytwo.size())
			frty++;
		f=fortytwo[frty];
		frty++;
		counter++;
		}
		if(counter==6){
			co++;
		}
	}

//	for(int i=0; i<43; i++)
//		s+=occ[i];
	s=n-(co*6);
	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;

	int occ[50]={0};

	unordered_set<int> m;

	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;

	int j=0,counter=0,a,b,c,d,e,f,co=0;
	int fr,ei=0,fit=0,six=0,sev=0,frty=0;
	for(int i=0; i<four.size();i++)
	{
		counter=1;
		a=four[i];

		if(ei<eight.size()){
		while(a>eight[ei])
			ei++;
		b=eight[ei];
		counter++;
		e++;
		}

		if(fit<fifteen.size()){
		while(b>fifteen[fit])
			fit++;
		c=fifteen[fit];
		fit++;
		counter++;
		}

		if(six<sixteen.size()){
		while(c>sixteen[six])
			six++;
		d=sixteen[six];
		six++;
		counter++;
		}

		if(sev<seventeen.size()){
		while(d>seventeen[sev])
			sev++;
		e=seventeen[sev];
		sev++;
		counter++;
		}

		if(frty<fortytwo.size()){
		while(e>fortytwo[frty])
			frty++;
		f=fortytwo[frty];
		frty++;
		counter++;
		}
		if(counter==6){
			co++;
		}
	}

	s=n-(co*6);
	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	long int occ[100]={0};
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;
	unordered_set<int> m;
	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;

	int j=0,counter=0,a,b,c,d,e,f,co=0;
	int fr,ei=0,fit=0,six=0,sev=0,frty=0;
	for(int i=0; i<four.size();i++)
	{
		counter=1;
		a=four[i];

		if(ei<eight.size()){
		while(a>eight[ei] && ei<eight.size())
			ei++;
		if(ei<eight.size()){
		b=eight[ei];
		counter++;
		ei++;
		}
		}
		else
			break;

		if(fit<fifteen.size()){
		while(b>fifteen[fit] && fit<fifteen.size())
			fit++;
		if(fit<fifteen.size()){
		c=fifteen[fit];
		fit++;
		counter++;
		}
		}
		else
			break;

		if(six<sixteen.size()){
		while(c>sixteen[six] && six<sixteen.size())
			six++;
		if(six<sixteen.size()){
		d=sixteen[six];
		six++;
		counter++;
		}
		}
		else
			break;

		if(sev<seventeen.size()){
		while(d>seventeen[sev] && sev<seventeen.size())
			sev++;
		if(sev<seventeen.size()){
		e=seventeen[sev];
		sev++;
		counter++;
		}
		}
		else
			break;

		if(frty<fortytwo.size()){
		while(e>fortytwo[frty] && frty<fortytwo.size())
			frty++;
		if(frty<fortytwo.size()){
		f=fortytwo[frty];
		frty++;
		counter++;
		}
		}
		else
			break;

		if(counter==6){
			co++;
		}
	}

	s=n-(co*6);
	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define SZ 5*100000+199
using namespace std;
int main()
{
	int n,v;
	int ar[SZ];
	long int occ[100]={0};
	vector<int>four;
	vector<int>eight;
	vector<int>fifteen;
	vector<int>sixteen;
	vector<int>seventeen;
	vector<int>fortytwo;
	unordered_set<int> m;
	cin>>n;

	for(int i=0; i<n; i++)
	{
		cin>>v;
		if(m.find(v)!=m.end())
		{
			occ[v]++;
		}
		else
		{
			m.insert(v);
			occ[v]++;
		}

		if(v==4)
		{
			four.push_back(i);
		}
		else if(v==8)
		{
			eight.push_back(i);
		}
		else if(v==15)
		{
			fifteen.push_back(i);
		}
		else if(v==16)
		{
			sixteen.push_back(i);
		}
		else if(v==23)
		{
			seventeen.push_back(i);
		}
		else if(v==42)
		{
			fortytwo.push_back(i);
		}

	}

	int i=0,s=0;

	int j=0,counter=0,a,b,c,d,e,f,co=0;
	int fr,ei=0,fit=0,six=0,sev=0,frty=0;
	for(int i=0; i<four.size();i++)
	{
		counter=1;
		a=four[i];

		if(ei<eight.size()){
		while(a>eight[ei] && ei<eight.size())
			ei++;
		b=eight[ei];
		counter++;
		ei++;
		}
		else
			break;

		if(fit<fifteen.size()){
		while(b>fifteen[fit] && fit<fifteen.size())
			fit++;
		c=fifteen[fit];
		fit++;
		counter++;
		}
		else
			break;

		if(six<sixteen.size()){
		while(c>sixteen[six] && six<sixteen.size())
			six++;
		d=sixteen[six];
		six++;
		counter++;
		}
		else
			break;

		if(sev<seventeen.size()){
		while(d>seventeen[sev] && sev<seventeen.size())
			sev++;
		e=seventeen[sev];
		sev++;
		counter++;
		}
		else
			break;

		if(frty<fortytwo.size()){
		while(e>fortytwo[frty] && frty<fortytwo.size())
			frty++;
		f=fortytwo[frty];
		frty++;
		counter++;
		}
		else
			break;

		if(counter==6){
			co++;
		}
	}

	s=n-(co*6);
	cout<<s<<endl;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>(b);i--)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 100001;

/*
struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};
*/

int arr[3*MAX_N];

void rarr(int n){
        rep(i,0,n)
            cin>>arr[i];
}

int cnt[3];

int main()
{
        #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                //freopen("output.txt", "w", stdout);
        #endif
        init_io();
        int n;
        int A[6]={4,8,15,16,23,42};
        map<int,vector<int> >m;
        cin>>n;
        rep(i,0,n)
        {
            cin>>arr[i];
            m[arr[i]].push_back(i);
        }
        rep(i,0,6)
            reverse(m[A[i]].begin(),m[A[i]].end());
        bool ok = true;
        int ans = 0;
        while(ok)
        {
            rep(i,0,6)
                if(m[A[i]].empty())
                    ok = false;
            int j=0;
            int idx = m[A[j]].back();
            m[A[j]].pop_back();
            j++;
            rep(i,0,5)
            {
                while(!m[A[j]].empty() && m[A[j]].back()<idx)
                    m[A[j]].pop_back();
                if(m[A[j]].empty()){ok=false;break;}
                idx = m[A[j]].back();
                m[A[j]].pop_back();
                j++;
            }
            if(ok)
                ans++;

        }
        cout<<(n-6*ans)<<endl;
        return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>(b);i--)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 100001;

/*
struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};
*/

int arr[5*MAX_N];

void rarr(int n){
        rep(i,0,n)
            cin>>arr[i];
}

int cnt[3];

int main()
{
        #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                //freopen("output.txt", "w", stdout);
        #endif
        init_io();
        int n;
        int A[6]={4,8,15,16,23,42};
        map<int,vector<int> >m;
        cin>>n;
        rep(i,0,n)
        {
            cin>>arr[i];
            m[arr[i]].push_back(i);
        }
        rep(i,0,6)
            reverse(m[A[i]].begin(),m[A[i]].end());
        bool ok = true;
        int ans = 0;
        while(ok)
        {
            rep(i,0,6)
                if(m[A[i]].empty())
                    ok = false;
		if(!ok)
break;
            int j=0;
            int idx = m[A[j]].back();
            m[A[j]].pop_back();
            j++;
            rep(i,0,5)
            {
                while(!m[A[j]].empty() && m[A[j]].back()<idx)
                    m[A[j]].pop_back();
                if(m[A[j]].empty()){ok=false;break;}
                idx = m[A[j]].back();
                m[A[j]].pop_back();
                j++;
            }
            if(ok)
                ans++;

        }
        cout<<(n-6*ans)<<endl;
        return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>(b);i--)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 100001;

/*
struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};
*/

int arr[3*MAX_N];

void rarr(int n){
        rep(i,0,n)
            cin>>arr[i];
}

int cnt[3];

int main()
{
        #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                //freopen("output.txt", "w", stdout);
        #endif
        init_io();
        int n;
        cin>>n;
        rep(i,0,n)
        {
            int x ;
            cin>>x;
            arr[x]++;
        }
        int mn = INT_MAX;
        mn = min(mn,arr[4]);
        mn = min(mn,arr[8]);
        mn = min(mn,arr[15]);
        mn = min(mn,arr[16]);
        mn = min(mn,arr[23]);
        mn = min(mn,arr[42]);
        cout<<(n-mn*6)<<endl;
        return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>(b);i--)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 100001;

/*
struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};
*/

int arr[3*MAX_N];

void rarr(int n){
        rep(i,0,n)
            cin>>arr[i];
}

int cnt[3];

int main()
{
        #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                //freopen("output.txt", "w", stdout);
        #endif
        init_io();
        int n;
        int A[6]={4,8,15,16,23,42};
        map<int,vector<int> >m;
        cin>>n;
        rep(i,0,n)
        {
            cin>>arr[i];
            m[arr[i]].push_back(i);
        }
        rep(i,0,6)
            reverse(m[A[i]].begin(),m[A[i]].end());
        bool ok = true;
        int ans = 0;
        while(ok)
        {
            rep(i,0,6)
                if(m[A[i]].empty())
                    ok = false;
	    	if(!ok)
                break;
            int j=0;
            int idx = m[A[j]].back();
            m[A[j]].pop_back();
            j++;
            rep(i,0,5)
            {
                while(!m[A[j]].empty() && m[A[j]].back()<idx)
                    m[A[j]].pop_back();
                if(m[A[j]].empty()){ok=false;break;}
                idx = m[A[j]].back();
                m[A[j]].pop_back();
                j++;
            }
            if(ok)
                ans++;

        }
        cout<<(n-6*ans)<<endl;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int a[7] = { 0, 4, 8, 15, 16, 23, 42 };
int n, b[7];

int main() {
	read(n);
	b[0] = MAXN;
	for (int x, i = 1; i <= n; ++i) {
		read(x);
		for (int j = 1; j <= 6; ++j)
			if (x == a[j] && b[j - 1]) {
				++b[j], --b[j - 1];
				break;
			}
	}
	write(n - b[6] * 6);
	putchar('\n');
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define INF  0x7fffffffffff//ffff
#define M 612345
ll n,x,a[M],ans = 0,flag,m;
int main(void){
	cin>>n;
	m = n;
	while(n--){
		cin>>x;
		flag = 1;
		if(x==4)
		a[0]++;
		else if(x==8&&a[1] <a[0])
		a[1]++;
		else if(x==15&&a[2] <a[1])
		a[2]++;
		else if(x==16&&a[3] <a[2])
		a[3]++;
		else if(x==23&&a[4] <a[3])
		a[4]++;
		else if(x==42&&a[5] <a[4])
		a[5]++;
		for(ll i = 0;i < 6;i++)
		if(!a[i])
		flag = 0;
		if(flag){
			for(ll i = 0;i < 6;i++)
			a[i]--;
			ans++;
		}
	}

	cout<<m - ans * 6<<endl;

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
	int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int q;
		cin>>q;
		if(q==4) a[1]++;
		if(q==8) a[2]++;
		if(q==15) a[3]++;
		if(q==16) a[4]++;
		if(q==23) a[5]++;
		if(q==42) a[6]++;
	}
	int minn=0x3f3f3f3f;
	for(int i=1;i<=6;i++)
	{
		minn=min(a[i],minn);
	}
	for(int i=1;i<=6;i++)
	{
		ans+=(a[i]-minn);
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define INF  0x7fffffffffff//ffff
#define M 612345
ll n,s,a,b,c,d,e;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int x;
        scanf("%d",&x);
        if(x==4)
            ++a;
        if(x==8){
            if(a==b)
                s++;
            else
                ++b;
        }
        if(x==15){
            if(a==c||b==c)
                s++;
            else
                ++c;
        }
        if(x==16)
            if(a==d||b==d||c==d)
                s++;
            else
                d++;
        if(x==23)
            if(a==e||b==e||c==e||d==e)
                s++;
            else
                e++;
        if(x==42)
            if(!a||!b||!c||!d||!e)
                s++;
            else
                --a,--b,--c,--d,--e;
    }
    printf("%d\n",s+a+b+c+d+e);
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
inline void write(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int a,b,c,d,e,s;
int main(){
	int n=read();
	while(n--){
		int x=read();
		if(x==4) a++;
		if(x==8){
			if(a==b) s++;
			else b++;
		}
		if(x==15){
			if(a==c||b==c) s++;
			else c++;
		}
		if(x==16){
			if(a==d||b==d||c==d) s++;
			else d++;
		}
		if(x==23){
			if(a==e||b==e||c==e||d==e) s++;
			else e++;
		}
		if(x==42){
			if(!a||!b||!c||!d||!e) s++;
			else a--,b--,c--,d--,e--;
		}
	}
	write(a+b+c+d+e+s);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int N,used1=1,used2=1,ans;
struct Seq{
	bool full;
	int nd=1;
	void pump()
	{
		nd++;
		if(nd==7)full=true;
	}
}a[500005];
inline int read()
{
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void Solve()
{
	N=read();
	int x=0;
	for(int i=1;i<=N;i++)
	{
		x=read();
		bool suc=false;
		switch(x)
		{
			case 4:x=1;break;
			case 8:x=2;break;
			case 15:x=3;break;
			case 16:x=4;break;
			case 23:x=5;break;
			case 42:x=6;break;
			default:ans++;
		}
		for(int i=1;i<=used1;i++)
		{
			if(a[i].full)continue;
			if(a[i].nd==x)
			{
				used2++;
				a[i].pump();
				suc=true;
				break;
			}
		}
		used1=used2;
		if(!suc)ans++;
	}
	for(int i=used1;i>=1;i--)
	{
		if(!a[i].full)
		{
			ans+=a[i].nd-1;
		}
	}
	cout<<ans;
}
int main()
{
	Solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[500005],N,cnt[7];
inline int read()
{
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void Solve()
{
	N=read();
	int x;
	for(int i=1;i<=N;i++)
	{
		x=read();
		switch(x)
		{
			case 4:a[i]=1;break;
			case 8:a[i]=2;break;
			case 15:a[i]=3;break;
			case 16:a[i]=4;break;
			case 23:a[i]=5;break;
			case 42:a[i]=6;break;
		}
	}
	for(int i=1;i<=N;i++)
	{
		if(a[i]==1)cnt[1]++;
		else
		{
			if(cnt[a[i]-1])
			{
				cnt[a[i]]++;
				cnt[a[i]-1]--;
			}
		}
	}
	cout<<N-6*cnt[6];
}
int main()
{
	Solve();
	return 0;
}


// luogu-judger-enable-o2
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int n;  int cnt[100];  int tmp;  int minn=0x3f3f3f3f;  int maxn;
int ans=0x3f3f3f3f;
int main(){
    scanf("%d",&n);
    while(n--){
        scanf("%d",&tmp);
        ++cnt[tmp];
    }
    minn=min(minn,cnt[4]);  minn=min(minn,cnt[8]);
    minn=min(minn,cnt[15]); minn=min(minn,cnt[16]);
    minn=min(minn,cnt[23]); minn=min(minn,cnt[42]);

    maxn=max(maxn,cnt[4]);  maxn=min(maxn,cnt[8]);
    maxn=max(maxn,cnt[15]); maxn=min(maxn,cnt[16]);
    maxn=max(maxn,cnt[23]); maxn=min(maxn,cnt[42]);
    for(int i=minn;i<=minn;++i){
        int sum=0;
        sum+=abs(i-cnt[4]);    sum+=abs(i-cnt[8]);
        sum+=abs(i-cnt[15]);   sum+=abs(i-cnt[16]);
        sum+=abs(i-cnt[23]);   sum+=abs(i-cnt[42]);
        ans=min(ans,sum);
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
#include<limits.h>
using namespace std;
#pragma GCC optimize(2)
int n;
int x;
int vis[10];
int mmin = INT_MAX;
int mmax;
int ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		if (x == 4)
			vis[0]++;
		if (x == 8 && vis[0])
		{
			vis[1]++;
			vis[0]--;
		}
		if (x == 15&&vis[1])
		{
			vis[2]++;
			vis[1]--;
		}
		if (x == 16 && vis[2])
		{
			vis[3]++;
			vis[2]--;
		}
		if (x == 23 && vis[3])
		{
			vis[4]++;
			vis[3]--;
		}
		if (x == 42 && vis[4])
		{
			vis[5]++;
			vis[4]--;
		}

	}
	for (int i = 0; i < 6; i++)
	{
		mmin = min(mmin, vis[i]);
		mmax = max(mmax, vis[i]);
	}
	for (int i = 0; i < 6; i++)
	{
		ans += vis[i] - mmin;
	}
	cout << n-6*vis[5];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define qomzi(n,i) for(register int i=1;i<=(n);++i)
#define INF 1e9

using namespace std;
inline int icin(){
	char c=getchar();int s=0;bool sign=0;
	while(!isdigit(c)&&c^'-')c=getchar();
	if(c=='-')c=getchar(),sign=1;
	while(isdigit(c))s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return sign?-s:s;
}

int N,tot,s1,s2,s3,s4,s5;

int main(){
	N=icin();
	while(N--){
		int x=icin();
		switch(x){
			case 4: s1++;break;
			case 8: s1==s2?tot++:s2++;break;
			case 15: s1==s3||s2==s3?tot++:s3++;break;
			case 16: s1==s4||s2==s4||s3==s4?tot++:s4++;break;
			case 23: s1==s5||s2==s5||s3==s5||s4==s5?tot++:s5++;break;
			default : break;
		}
		if(x==42){
			if(!s1||!s2||!s3||!s4||!s5) tot++;
			else
			   s1--,s2--,s3--,s4--,s5--;
		}
	}
	printf("%d\n",tot+s1+s2+s3+s4+s5);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 500005;
int a[MAXN];
int cnt[7];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if (x==4) x=1;
        if (x==8) x=2;
        if (x==15) x=3;
        if (x==16) x=4;
        if (x==23) x=5;
        if (x==42) x=6;
        a[i]=x;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==1)
            cnt[1]++;
        else
        {
            if(cnt[a[i]-1])
            {
                cnt[a[i]]++;
                cnt[a[i]-1]--;
            }
        }
    }
    cout<<n-6*cnt[6]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=500005;
const int mod = 1e9+7;
int n;
queue < int > q[10];
int a[maxn];
int b[] = {4,8,15,16,23,42};
int f[100];
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
rep(i,0,6) while(sz(q[i])) q[i].pop();
	rep(i,0,n) cin>>a[i], q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) ans++, q[i].pop();
			if(!sz(q[i])){
				rep(i,0,6) ans+= sz(q[i]);
				ans += i;
				cout << ans;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=500005;
const int mod = 1e9+7;
int n;
queue < int > q[8];
int a[maxn];
int b[] = {4,8,15,16,23,42};
int f[5];
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
	rep(i,0,n) cin>>a[i], q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) q[i].pop();
			if(!sz(q[i])){
				cout << n - ans*6;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
		ans ++;
	}
	cout << n-ans*6;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=500005;
const int mod = 1e9+7;
int n;
queue < int > q[8];
int a[maxn];
int b[] = {4,8,15,16,23,42};
int f[5];
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
	rep(i,0,n) cin>>a[i], q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) ans++, q[i].pop();
			if(!sz(q[i])){
				rep(i,0,6) ans+= sz(q[i]);
				ans += i;
				cout << ans;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=1000005;
const int mod = 1e9+7;
int n;
queue < int > q[maxn];
int a[maxn];
int b[] = {4,8,15,16,23,42};
map <int ,int > f;
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
	rep(i,0,n) cin>>a[i],q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) ans++, q[i].pop();
			if(!sz(q[i])){
				rep(i,0,6) ans+= sz(q[i]);
				ans += i;
				cout << ans;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=500005;
const int mod = 1e9+7;
int n;
queue < int > q[maxn];
int a[maxn];
int b[] = {4,8,15,16,23,42};
map <int ,int > f;
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
	rep(i,0,n) cin>>a[i],q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) ans++, q[i].pop();
			if(!sz(q[i])){
				rep(i,0,6) ans+= sz(q[i]);
				ans += i;
				cout << ans;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
	}
	cout << ans;
	return 0;
}


 #include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=500005;
const int mod = 1e9+7;
int n;
queue < int > q[8];
int a[maxn];
int b[] = {4,8,15,16,23,42};
int f[105];
int ans;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>> n;
	rep(i,0,6) f[b[i]]=i;
	rep(i,0,n) cin>>a[i], q[f[a[i]]].push(i);
	while(sz(q[0])){
		int t=q[0].front();
		q[0].pop();
		rep(i,1,6){
			while(sz(q[i])&&q[i].front()<t) q[i].pop();
			if(!sz(q[i])){
				cout << n - ans*6;
				return 0;
			}
			t=q[i].front();
			q[i].pop();
		}
		ans ++;
	}
	cout << n-ans*6;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;
const int ma = 500010;
int n,num[ma];
vector<int> v[ma],nu[10];

int main()
{
    scanf("%d",&n);
    int in = -1;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num[i]);
        if(num[i] == 4)
            v[++in].push_back(i);
        if(num[i] == 8)
            nu[0].push_back(i);
        if(num[i] == 15)
            nu[1].push_back(i);
        if(num[i] == 16)
            nu[2].push_back(i);
        if(num[i] == 23)
            nu[3].push_back(i);
        if(num[i] == 42)
            nu[4].push_back(i);
    }
    int ans = 0;
    for(int i = 0;i < 5;i++)
    {
        in = 0;
        for(int j = 0;j < nu[i].size();j++)
            if(nu[i][j] > v[in][i])
            {
                v[in++].push_back(nu[i][j]);
            }
            else
                ans++;
    }
    for(int i = 0;i <= in;i++)
    {
        if(v[i].size() == 6)
            continue;
        ans += v[i].size();
    }
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;
const int ma = 500010;
int n,num[ma];
vector<int> v[ma],nu[10];

int main()
{
    scanf("%d",&n);
    int in = -1;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num[i]);
        if(num[i] == 4)
            v[++in].push_back(i);
        if(num[i] == 8)
            nu[0].push_back(i);
        if(num[i] == 15)
            nu[1].push_back(i);
        if(num[i] == 16)
            nu[2].push_back(i);
        if(num[i] == 23)
            nu[3].push_back(i);
        if(num[i] == 42)
            nu[4].push_back(i);
    }
    int ans = 0;
    for(int i = 0; i < 5; i++)
    {
        int in1 = 0;
        for(int j = 0; j < nu[i].size(); j++)
        {
            if(v[in1].size() == i+1 && nu[i][j] > v[in1][i])
            {
                v[in1++].push_back(nu[i][j]);
            }
            else
                ans++;
        }
    }
    for(int i = 0; i <= in; i++)
    {
        if(v[i].size() == 6)
            continue;
        ans += v[i].size();
    }
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;
const int ma = 5e5 + 10;
int n,num[ma];
vector<int> v[ma],nu[5];

int main()
{
    scanf("%d",&n);
    int in = -1;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num[i]);
        if(num[i] == 4)
            v[++in].push_back(i);
        if(num[i] == 8)
            nu[0].push_back(i);
        if(num[i] == 15)
            nu[1].push_back(i);
        if(num[i] == 16)
            nu[2].push_back(i);
        if(num[i] == 23)
            nu[3].push_back(i);
        if(num[i] == 42)
            nu[4].push_back(i);
    }
    int ans = 0;
    for(int i = 0;i < 5;i++)
    {
        in = 0;
        for(int j = 0;j < nu[i].size();j++)
            if(nu[i][j] > v[in][i])
            {
                v[in++].push_back(nu[i][j]);
            }
            else
                ans++;
    }

//    for(int i = 0;i <= in;i++)
//    {
//        for(int j = 0;j < v[i].size();j++)
//            cout<<v[i][j]<<" ";
//        cout<<endl;
//    }
    for(int i = 0;i <= in;i++)
    {
        if(v[i].size() == 6)
            continue;
        ans += v[i].size();
    }
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;
const int ma = 500010;
int n,num[ma];
vector<int> v[ma],nu[10];

int main()
{
    scanf("%d",&n);
    int in = -1;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num[i]);
        if(num[i] == 4)
            v[++in].push_back(i);
        if(num[i] == 8)
            nu[0].push_back(i);
        if(num[i] == 15)
            nu[1].push_back(i);
        if(num[i] == 16)
            nu[2].push_back(i);
        if(num[i] == 23)
            nu[3].push_back(i);
        if(num[i] == 42)
            nu[4].push_back(i);
    }
    int ans = 0;
    for(int i = 0;i < 5;i++)
    {
        in = 0;
        for(int j = 0;j < nu[i].size();j++)
            if(nu[i][j] > v[in][i] && v[in].size() == i+1)
            {
                v[in++].push_back(nu[i][j]);
            }
            else
                ans++;
    }
    for(int i = 0;i <= in;i++)
    {
        if(v[i].size() == 6)
            continue;
        ans += v[i].size();
    }
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;
const int ma = 500010;
int n,num[ma];
vector<int> v[ma],nu[10];

int main()
{
    scanf("%d",&n);
    int in = -1;
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&num[i]);
        if(num[i] == 4)
            v[++in].push_back(i);
        if(num[i] == 8)
            nu[0].push_back(i);
        if(num[i] == 15)
            nu[1].push_back(i);
        if(num[i] == 16)
            nu[2].push_back(i);
        if(num[i] == 23)
            nu[3].push_back(i);
        if(num[i] == 42)
            nu[4].push_back(i);
    }
    int ans = 0;
    for(int i = 0;i < 5;i++)
    {
        in = 0;
        for(int j = 0;j < nu[i].size();j++)
            if(v[in].size() == i+1&&nu[i][j] > v[in][i]  )
            {
                v[in++].push_back(nu[i][j]);
            }
            else
                ans++;
    }
    for(int i = 0;i <= in;i++)
    {
        if(v[i].size() == 6)
            continue;
        ans += v[i].size();
    }
    printf("%d",ans);
    return 0;
}


#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
#define n 500000
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
const lli mod = 1e9 + 7;
int a, b, c, d, e, f, temp, cnt, ans, mx, mi;
int arr[n + 50], arr2[n + 50];
struct thing{
	int thing;
}thing[n + 50];
bool cmp(int a, int b)
{
	return a > b;
}

////////////////////////////////

void solve()
{
	cin >> a;
	loop(i, 0, a - 1) cin >> arr[i];
	int yes[50] = {0};
	int table[30] = {0};
	table[4] = 1; table[8] = 2; table[15] = 3;
	table[16] = 4;table[23] = 5;table[42] = 6;
	yes[0] = INF;
	loop(i, 0, a - 1)
	{
		if(yes[table[arr[i]] - 1])
		{
			yes[table[arr[i]] - 1] --;
			yes[table[arr[i]]] ++;
		}
	}
	int ans = a - (yes[6] * 6);
	cout << ans;
}

int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}


#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
#define n 200000
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
const lli mod = 1e9 + 7;
int a, b, c, d, e, f, temp, cnt, ans, mx, mi;
int arr[n + 50], arr2[n + 50];
struct thing{
	int thing;
}thing[n + 50];
bool cmp(int a, int b)
{
	return a > b;
}

////////////////////////////////

void solve()
{
	cin >> a;
	loop(i, 0, a - 1) cin >> arr[i];
	int yes[50] = {0};
	int table[30] = {0};
	table[4] = 1; table[8] = 2; table[15] = 3;
	table[16] = 4;table[23] = 5;table[42] = 6;
	yes[0] = INF;
	loop(i, 0, a - 1)
	{
		if(yes[table[arr[i]] - 1])
		{
			yes[table[arr[i]] - 1] --;
			yes[table[arr[i]]] ++;
		}
	}
	int ans = a - (yes[6] * 6);
	cout << ans;
}

int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}


#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
#define n 200000
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
const lli mod = 1e9 + 7;
int a, b, c, d, e, f, temp, cnt, ans, mx, mi;
int arr[n + 50], arr2[n + 50];
struct thing{
	int thing;
}thing[n + 50];
bool cmp(int a, int b)
{
	return a > b;
}

////////////////////////////////

void solve()
{
	cin >> a;
	loop(i, 0, a - 1) cin >> arr[i];
	int yes[6];
	mem(yes);
	int table[30];
	table[4] = 0; table[8] = 1; table[15] = 2;
	table[16] = 3;table[23] = 4;table[42] = 5;
	cnt = 0;
	loop(i, 0, a - 1)
	{
		if(arr[i] == 4) yes[0] ++;
		else if(arr[i] == 42)
		{
			if(yes[4])
			{
				yes[4] --;
				cnt ++;
			}
		}
		else
		{
			if(yes[table[arr[i]] - 1])
			{
				yes[table[arr[i]] - 1] --;
				yes[table[arr[i]]] ++;
			}
		}
	}
	int ans = a - (cnt * 6);
	cout << ans;
}

int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}


#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
const int n = 500000;
int a, b, c, d, e, f, temp, cnt, ans, mx, mi;
int arr[n + 50];

////////////////////////////////

void solve()
{
	cin >> a;
	loop(i, 0, a - 1) cin >> arr[i];
	int yes[50] = {0};
	int table[500] = {0};
	table[4] = 1; table[8] = 2; table[15] = 3;
	table[16] = 4;table[23] = 5;table[42] = 6;
	yes[0] = n + 50;
	loop(i, 0, a - 1)
	{
		if(yes[table[arr[i]] - 1] > 0)
		{
			yes[table[arr[i]] - 1] --;
			yes[table[arr[i]]] ++;
		}
	}
	int ans = a - (yes[6] * 6);
	cout << ans;
}

int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}


#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
#define n 500000
using namespace std;
int a, b, c, d, e, f, temp, cnt, ans, mx, mi;
int arr[n + 50];
struct thing{
	int thing;
}thing[n + 50];
bool cmp(int a, int b)
{
	return a > b;
}

////////////////////////////////

void solve()
{
	cin >> a;
	loop(i, 0, a - 1) cin >> arr[i];
	int yes[50] = {0};
	int table[30] = {0};
	table[4] = 1; table[8] = 2; table[15] = 3;
	table[16] = 4;table[23] = 5;table[42] = 6;
	yes[0] = n + 50;
	loop(i, 0, a - 1)
	{
		if(yes[table[arr[i]] - 1])
		{
			yes[table[arr[i]] - 1] --;
			yes[table[arr[i]]] ++;
		}
	}
	int ans = a - (yes[6] * 6);
	cout << ans;
}

int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int prev(int k){
	vector<int> ans{4, 8, 15, 16, 23, 42};
	for (int i = 0; i < 6; i++){
		if (ans[i] == k)		return ans[i - 1];
	}
	return 0;
}
int main()
{
	int n, k;
	cin >> n;
	vector<int> check(43, 0);
	int ans = 0;
	for (int i = 1; i <= n; i++){
		cin >> k;
		if (k == 4){
			check[4]++;
		}
		else {
			int p = prev(k);
			if (check[p] == 0)		ans++;
			else {
				check[k]++;
				check[p]--;
			}
		}
	}
	ans += check[4];
	ans += check[8] * 2;
	ans += check[15] * 3;
	ans += check[16] * 4;
	ans += check[23] * 5;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int retind(int& k){
	vector<int> ans{4, 8, 15, 16, 23, 42};
	for (int i = 0; i < 6; i++){
		if (ans[i] == k)	return ans[i - 1];
	}
	return 0;
}

int main(){
	vector<int> nums;
	int n, e;
	scanf("%d", &n);
	int ans = 0;
	vector<int> check[n];
	int k = -1;
	int q = 0;
	for (int i = 1; i <= n; i++){
		cin >> e;
		if (e == 4){
			if (check[q].size() == 0){
				check[q].push_back(4);
				if (k < q)	k = q;
			}
			else{
				k++;
				check[k].push_back(4);
			}
		}
		else {
			int index = retind(e);
			int p = 0;
			for (int j = 0; j <= k; j++){
				int s = check[j].size() - 1;
				if (check[j][s] == index)
				{
					check[j].push_back(e);
					if (e == 42)		{check[j].clear(); q = j;}
					p = 1;
					break;
				}
			}
			if (p == 0)		ans++;
		}
	}
	for (int i = 0; i <= k; i++){
		int s = check[i].size() - 1;
		if (check[i][s] != 42)		ans += s + 1;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int retind(int k){
	vector<int> ans{4, 8, 15, 16, 23, 42};
	for (int i = 0; i < 6; i++){
		if (ans[i] == k)	return ans[i - 1];
	}
	return 0;
}

int retmin(vector<int>& nums){
	int ans = 0;
	vector<int> check[nums.size()];
	int k = -1;
	for (int i = 0; i < nums.size(); i++){
		if (nums[i] == 4){
			k++;
			check[k].push_back(4);

		}
		else {
			int index = retind(nums[i]);
			int p = 0;
			for (int j = 0; j <= k; j++){
				int s = check[j].size() - 1;
				if (check[j][s] == index)	{check[j].push_back(nums[i]); p = 1; break;}
			}
			if (p == 0)		ans++;
		}
	}
	for (int i = 0; i <= k; i++){
		int s = check[i].size() - 1;
		if (check[i][s] != 42)		ans += s + 1;
	}
	return ans;
}

int main(){
	vector<int> nums;
	int n, k;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		cin >> k;
		nums.push_back(k);
	}
	cout << retmin(nums) << endl;
}


#include <bits/stdc++.h>

using namespace std;

int retind(int k){
	vector<int> ans{4, 8, 15, 16, 23, 42};
	for (int i = 0; i < 6; i++){
		if (ans[i] == k)	return ans[i - 1];
	}
	return 0;
}

int retmin(vector<int>& nums){
	int ans = 0;
	vector<int> check[nums.size() / 6 + 1];
	int k = -1;
	int q = 0;
	for (int i = 0; i < nums.size(); i++){
		if (nums[i] == 4){
			if (check[q].size() == 0){
				check[q].push_back(4);
				if (k < q)	k = q;
			}
			else{
				k++;
				check[k].push_back(4);
			}
		}
		else {
			int index = retind(nums[i]);
			int p = 0;
			for (int j = 0; j <= k; j++){
				int s = check[j].size() - 1;
				if (check[j][s] == index)
				{
					check[j].push_back(nums[i]);
					if (nums[i] == 42)		{check[j].clear(); q = j;}
					p = 1;
					break;
				}
			}
			if (p == 0)		ans++;
		}
	}
	for (int i = 0; i <= k; i++){
		int s = check[i].size() - 1;
		if (check[i][s] != 42)		ans += s + 1;
	}
	return ans;
}

int main(){
	vector<int> nums;
	int n, k;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		cin >> k;
		nums.push_back(k);
	}
	cout << retmin(nums) << endl;
}


#include <bits/stdc++.h>

using namespace std;

int retind(int k){
	vector<int> ans{4, 8, 15, 16, 23, 42};
	for (int i = 0; i < 6; i++){
		if (ans[i] == k)	return ans[i - 1];
	}
	return 0;
}

int retmin(vector<int>& nums){
	int ans = 0;
	vector<int> check[nums.size() / 6 + 1];
	int k = -1;
	for (int i = 0; i < nums.size(); i++){
		if (nums[i] == 4){
			k++;
			check[k].push_back(4);

		}
		else {
			int index = retind(nums[i]);
			int p = 0;
			for (int j = 0; j <= k; j++){
				int s = check[j].size() - 1;
				if (check[j][s] == index)	{check[j].push_back(nums[i]); p = 1; break;}
			}
			if (p == 0)		ans++;
		}
	}
	for (int i = 0; i <= k; i++){
		int s = check[i].size() - 1;
		if (check[i][s] != 42)		ans += s + 1;
	}
	return ans;
}

int main(){
	vector<int> nums;
	int n, k;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		cin >> k;
		nums.push_back(k);
	}
	cout << retmin(nums) << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 110;
int N;
int a[maxn], pos[maxn];
int num[10] = {0, 4, 8, 15, 16, 23, 42};

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i ++) {
        scanf("%d", &a[i]);

        int t = lower_bound(num + 1, num + 1 + 6, a[i]) - num;

        if(t == 1) ++ pos[1];
        else {
            if(pos[t - 1] > 0) {
                -- pos[t - 1];
                ++ pos[t];
            }
        }
    }

    printf("%d\n", N - 6 * pos[6]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 110;
int N;
int a[maxn], pos[maxn];
int num[110] = {0, 4, 8, 15, 16, 23, 42};

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i ++) {
        scanf("%d", &a[i]);

        int t = lower_bound(num + 1, num + 1 + 6, a[i]) - num;

        if(t == 1) ++ pos[1];
        else {
            if(pos[t - 1] > 0) {
                -- pos[t - 1];
                ++ pos[t];
            }
        }
    }

    printf("%d\n", N - 6 * pos[6]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 110;
int N;
int a[maxn], pos[maxn];
int num[7] = {0, 4, 8, 15, 16, 23, 42};

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i ++) {
        scanf("%d", &a[i]);

        int t = lower_bound(num + 1, num + 1 + 6, a[i]) - num;

        if(t == 1) ++ pos[1];
        else {
            if(pos[t - 1] > 0) {
                -- pos[t - 1];
                ++ pos[t];
            }
        }
    }

    printf("%d\n", N - 6 * pos[6]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 10;
int N;
int a[maxn];
int vis[110];
int num[10] = {4, 8, 15, 16, 23, 42};

int main() {
    memset(vis, 0, sizeof(vis));
    scanf("%d", &N);
    int ans = 0;

    for(int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
        vis[a[i]] ++;
    }

    if(N < 6) ans = N;

    int minn = min(vis[4], min(vis[8], min(vis[15], min(vis[16], min(vis[23], vis[42])))));

    if(minn == 0) ans = N;
    else {
        for(int i = 0; i < 6; i ++)
            ans += (vis[num[i]] - minn);
    }

    printf("%d\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 10;
int N;
int a[maxn], pos[maxn];
int num[7] = {0, 4, 8, 15, 16, 23, 42};

int main() {

    memset(pos, 0, sizeof(pos));

    scanf("%d", &N);
    for(int i = 1; i <= N; i ++) {
        scanf("%d", &a[i]);

        int t = lower_bound(num + 1, num + 1 + 6, a[i]) - num;

        if(t == 1) ++ pos[1];
        else {
            if(pos[t - 1] > 0) {
                -- pos[t - 1];
                ++ pos[t];
            }
        }

    }

    printf("%d\n", N - 6 * pos[6]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 10;
int N;
int a[maxn];
int vis[10];
int num[10] = {4, 8, 15, 16, 23, 42};

int main() {
    memset(vis, 0, sizeof(vis));
    scanf("%d", &N);
    int ans = 0;

    for(int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
        vis[a[i]] ++;
    }

    if(N < 6) ans = N;

    int minn = min(vis[4], min(vis[8], min(vis[15], min(vis[16], min(vis[23], vis[42])))));

    if(minn == 0) ans = N;
    else {
        for(int i = 0; i < 6; i ++)
            ans += (vis[num[i]] - minn);
    }

    printf("%d\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[1009];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 1000; ++ i)
    {
        cnt += a[i].size() / 6;
    }
    cout << n - cnt * 6;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[1009];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 1000; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 1000; ++ i)
    {
        cnt += a[i].size() / 6;
    }
    cout << n - cnt * 6;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[84000];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 60 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 60; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 60; ++ i)
    {
        cnt += a[i].size() / 6;
    }
    cout << n - cnt * 6;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[1000009];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 5000; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 5000; ++ i)
    {
        cnt += a[i].size() / 6;
    }
    cout << n - cnt * 6;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[69];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 100 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 100; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 100; ++ i)
    {
        cnt += a[i].size() / 6;
    }
    cout << n - cnt * 6;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, a[500009], d[45], res;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        ++ d[a[i]];
    }
    if(n < 6)
    {
        cout << n;
        return 0;
    }
    res = min(d[4], d[8]);
    res = min(res, d[15]);
    res = min(res, d[16]);
    res = min(res, d[23]);
    res = min(res, d[42]);
    res *= 6;
    cout << n - res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[84000];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 83333; ++ j)
            {
                if(a[j].size() == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 83333; ++ i)
    {
        if(a[i].empty()) break;
        if(a[i].size() == 6) cnt += 6;
        else continue;
    }
    cout << n - cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
vector<int> a[84000];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        int x;
        cin >> x;
        if(x == 4)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 0)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 8)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 1)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 15)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 2)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 16)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 3)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 23)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 4)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
        else if(x == 42)
        {
            for(int j = 1; j <= 6; ++ j)
            {
                if(a[j].size() % 6 == 5)
                {
                    a[j].push_back(x);
                    break;
                }
            }
        }
    }
    if(n <= 5)
    {
        cout << n;
        return 0;
    }
    for(int i = 1; i <= 6; ++ i)
    {
        if(a[i].empty()) break;
        if(a[i].size() == 6) cnt += 6;
        else continue;
    }
    cout << n - cnt;
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;

ll n,a[100];

inline ll read(){
    ll x=0,tmp=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') tmp=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=(x<<3)+(x<<1)+ch-48;
        ch=getchar();
    }
    return tmp*x;
}

int main(){
    n=read();
    for(ll i=1; i<=n; i++){
        switch(read()){
            case 4:{
                a[i]=1;
                break;
            }
            case 8:{
                a[i]=2;
                break;
            }
            case 15:{
                a[i]=3;
                break;
            }
            case 16:{
                a[i]=4;
                break;
            }
            case 23:{
                a[i]=5;
                break;
            }
            case 42:{
                a[i]=6;
                break;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll x;
        if(a[i]==1){
            a[i]=0; x=1;
            for(ll j=i+1; j<=n; j++){
                if(a[j]==x+1){
                    x=a[j];
                    a[j]=0;
                }
            }
        }
        if(x!=6){
            ll sum=0;
            for(ll i=1; i<=n; i++){
                if(a[i]) sum++;
            }
            cout<<sum+x<<endl;
            return 0;
        }
    }
    ll sum=0;
    for(ll i=1; i<=n; i++){
        if(a[i]) sum++;
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int arr[200000];

  int n, k, num;

  cin >> n >> k;

  for(int i = 0; i < n; i++)
    arr[i] = -1;

  for(int i = 0; i < n; i++)
    {
      cin >> num;
      arr[i] = num;
    }

  sort(arr, arr + n);

    if(k == 0)
    {
      if(arr[0] == 1)
	cout << 1;
      else
	cout << -1;
    }

  if(arr[k-1] != arr[k])
    cout << arr[k-1];
  else
    cout << -1;

  //for(int i = 0; i < n; i++)
  //  cout << arr[i];

  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int arr[200000];

  int n, k, num;

  cin >> n >> k;

  for(int i = 0; i < n; i++)
    arr[i] = -1;

  for(int i = 0; i < n; i++)
    {
      cin >> num;
      arr[i] = num;
    }

  sort(arr, arr + n);

  if(k == 0)
    {
      if(arr[0] > 1)
	{
	cout << 1;
	return 0;
	}
      else
	{
	cout << -1;
	return 0;
	}
    }

  if(arr[k-1] != arr[k])
    cout << arr[k-1];
  else
    cout << -1;

  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int arr[200000];

  int n, k, num;

  cin >> n >> k;

  for(int i = 0; i < n; i++)
    arr[i] = -1;

  for(int i = 0; i < n; i++)
    {
      cin >> num;
      arr[i] = num;
    }

  sort(arr, arr + n);

    if(k == 0)
    {
      if(arr[0] == 1)
	cout << 1;
      else
	cout << -1
    }

  if(arr[k-1] != arr[k])
    cout << arr[k-1];
  else
    cout << -1;

  //for(int i = 0; i < n; i++)
  //  cout << arr[i];

  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int arr[200000];

  int n, k, num;

  cin >> n >> k;

  for(int i = 0; i < n; i++)
    arr[i] = -1;

  for(int i = 0; i < n; i++)
    {
      cin >> num;
      arr[i] = num;
    }

  sort(arr, arr + n);

  if(k == 0)
    {
      if(arr[0] == 0)
	cout << -1;
      else
	cout << 0;
    }

  if(arr[k-1] != arr[k])
    cout << arr[k-1];
  else
    cout << -1;

  //for(int i = 0; i < n; i++)
  //  cout << arr[i];

  return 0;
}


int main()
{
  int arr[200000];

  int n, k, num;

  cin >> n >> k;

  for(int i = 0; i < n; i++)
    arr[i] = -1;

  for(int i = 0; i < n; i++)
    {
      cin >> num;
      arr[i] = num;
    }

  sort(arr, arr + n);

    if(k == 0)
    {
      if(arr[0] == 0)
	cout << -1;
      else
	cout << 1;
    }

  if(arr[k-1] != arr[k])
    cout << arr[k-1];
  else
    cout << -1;

  //for(int i = 0; i < n; i++)
  //  cout << arr[i];

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[0] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> k;

    for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[1] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }

    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0 && n == 1)
    {
        if(a[0] != 0 && a[0] == 1)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
      if(k == 0 && n > 1)
    {
        if(a[0] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k] && k > 0)
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> k;

    for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[1] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        return 0;

    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[1] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0 && n == 1)
    {
        if(a[0] != 0 && a[0] == 1)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[0] != 0 && a[0] == 1)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> k;

    for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[1] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
   cin >> n >> k;

       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0)
    {
        if(a[1] != 0)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k])
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
    if(k == 0 && n == 1)
    {
        if(a[0] != 0 && a[0] == 1)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
      if(k == 0 && n > 1)
    {
        if(a[0] != 1)
            cout << "1" << endl;
        else
        {
            cout << "-1" << endl;
        }
        continue;
    }
    sort(a,a+n);
    if(a[k - 1] != a[k] && k > 0)
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300000];
int main()
{
    int n,k;
    ios::sync_with_stdio(0),cin.tie(0);
    while(cin >> n >> k)
    {
       for(int i =0 ; i < n; i ++)
    {
        cin >> a[i];
    }
       sort(a,a+n);
    if(k == 0 && n == 1)
    {
        if(a[0] != 0 && a[0] == 1)
            cout << "-1" << endl;
        else
        {
            cout << "1" << endl;
        }
        continue;
    }
      if(k == 0 && n > 1)
    {
        if(a[0] != 1)
            cout << "1" << endl;
        else
        {
            cout << "-1" << endl;
        }
        continue;
    }

    if(a[k - 1] != a[k] && k > 0)
    {
        cout << a[k - 1] << endl;
    }
    else
        cout << "-1" << endl;
    }
    return 0;

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(k);
		/* code */
	}
	sort(v.begin(),v.end());

	if(a[k-1]!=a[k])
	{
        cout<<a[k-1]+1<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else
	    cout<<v[0]-1<<"\n";
	}
	else{

	if(v[k-1]!=v[k])
	{
        cout<<v[k-1]+1<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());

	if(v[k-1]!=v[k])
	{
        cout<<v[k-1]+1<<"\n";
	}
	else if(v[k-1]==v[k])
	{
		cout<<"-1"<<"\n";
	}

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{if(v[0]==1)
	    cout<<"-1"<<"\n";
	    else if(v[0]-1>=pow(10,9))
	    cout<<v[0]-1<<"\n";
	    else cout<<"-1"<<"\n":
	}
	else{

	if(v[k-1]!=v[k])
	{ if(v[k-1]>=pow(10,9))
        cout<<v[k-1]<<"\n";
        else cout<<"-1"<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}
}
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for (int i = 0; i < n; ++i)
	{int f;
		cin>>f;
		v.push_back(f);
		/* code */
	}
	sort(v.begin(),v.end());
	if(k==0)
	{cout<<"-1"<<"\n";}
	else{

	if(v[k-1]!=v[k])
	{
        cout<<v[k-1]+1<<"\n";
	}
	else
	{
		cout<<"-1"<<"\n";
	}
}
}