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