#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, x, c = 0, b[6] = {4, 8, 15, 16, 23, 42};
  cin >> n;
  queue<long long> q[6];
  for (long long i = 0; i < n; i++) {
    cin >> x;
    switch (x) {
      case 4:
        q[0].emplace(i);
        break;
      case 8:
        q[1].emplace(i);
        break;
      case 15:
        q[2].emplace(i);
        break;
      case 16:
        q[3].emplace(i);
        break;
      case 23:
        q[4].emplace(i);
        break;
      case 42:
        q[5].emplace(i);
        break;
    }
  }
  while (1) {
    long long y, z, f = 1;
    for (long long i = 0; i < 6; i++) {
      if (!q[i].empty()) {
        if (i == 0) {
          y = q[i].front();
          q[i].pop();
        } else {
          z = q[i].front();
          q[i].pop();
          while (!q[i].empty() && y > z) {
            z = q[i].front();
            q[i].pop();
          }
          if (y < z) {
            y = z;
          } else {
            f = 0;
            break;
          }
        }
      } else {
        f = 0;
        break;
      }
    }
    if (f == 1) {
      c += 6;
    } else {
      break;
    }
  }
  cout << n - c;
  return 0;
}
