#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
  return a.second < b.second;
}
int main() {
  long long n, m = 100001;
  cin >> n;
  long long a[n], p[100] = {0}, c[6] = {4, 8, 15, 16, 23, 42};
  for (long long i = 0; i < n; i++) cin >> a[i];
  if (n < 6)
    cout << n;
  else {
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] == 42) p[42]++;
      if (a[i] == 23 && p[23] + 1 <= p[42]) p[23]++;
      if (a[i] == 16 && p[16] + 1 <= p[23]) p[16]++;
      if (a[i] == 15 && p[15] + 1 <= p[16]) p[15]++;
      if (a[i] == 8 && p[8] + 1 <= p[15]) p[8]++;
      if (a[i] == 4 && p[4] + 1 <= p[8]) p[4]++;
    }
    for (long long i = 0; i < 6; i++) m = min(m, p[c[i]]);
    cout << n - m * 6;
  }
}
