#!/usr/bin/env python3 n = int(input()) s = input() s = ''.join(s.split('3')) s = ''.join(s.split('5')) s = ''.join(s.split('7')) ans = n - len(s) one = 0 nine = 0 nine_nine = 0 for c in s: if c == '1': if one > 0: ans += 1 one -= 1 elif nine_nine > 0: ans += 1 nine -= 2 nine_nine -= 1 else: one += 1 if c == '9': if one > 0: ans += 1 one -= 1 elif nine > 0: nine += 1 nine_nine += 1 else: nine += 1 print(ans)