#include <bits/stdc++.h>
using namespace std;
int aa[500010];
int main() {
  int n, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, s6 = 0, ss = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &aa[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (aa[i] == 4)
      s1++;
    else if (aa[i] == 8) {
      if (s1 > 0) {
        s1--;
        s2++;
      } else
        ss++;
    } else if (aa[i] == 15) {
      if (s2 > 0) {
        s2--;
        s3++;
      } else
        ss++;
    } else if (aa[i] == 16) {
      if (s3 > 0) {
        s3--;
        s4++;
      } else
        ss++;
    } else if (aa[i] == 23) {
      if (s4 > 0) {
        s4--;
        s5++;
      } else
        ss++;
    } else if (aa[i] == 42) {
      if (s5 > 0) {
        s5--;
        s6++;
      } else
        ss++;
    }
  }
  printf("%d\n", ss + s1 + s2 * 2 + s3 * 3 + s4 * 4 + s5 * 5);
}
