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