#include <bits/stdc++.h>
using namespace std;
long long n, a[500005], itr[6], mx;
vector<long long> v[6];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 4) v[0].push_back(i);
    if (a[i] == 8) v[1].push_back(i);
    if (a[i] == 15) v[2].push_back(i);
    if (a[i] == 16) v[3].push_back(i);
    if (a[i] == 23) v[4].push_back(i);
    if (a[i] == 42) v[5].push_back(i);
  }
  for (long long i = 0; i < v[0].size(); i++) {
    mx = v[0][i];
    for (long long j = 1; j <= 5; j++) {
      while ((itr[j] < v[j].size()) && (v[j][itr[j]] <= mx)) itr[j]++;
      if ((itr[j] == v[j].size())) {
        cout << n - (i * 6);
        return 0;
      }
      mx = v[j][itr[j]];
      itr[j]++;
    }
  }
  cout << n - (v[0].size() * 6);
}
