#!/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 i in range(len(s)): if s[i] == '1': if one > 0: ans += 1 one -= 1 if nine_nine > 0: ans += 1 nine -= 2 nine_nine -= 1 else: one += 1 if s[i] == '9': if one > 0: ans += 1 one -= 1 if nine > 0: nine_nine += 1 print(ans)