ss = int(input()) a=[i for i in range(120)] n_str=input() n_int=int(n_str) n_str_list=list(n_str) n_int_list=sorted([int(i) for i in n_str_list]) exchange_list_1 = [] exchange_list_10 = [] exchange_list_100 = [] n_div_120 = 0 for i in n_int_list: n_div_120 += i n_div_120 = n_div_120 % 120 three_list = [n_int_list[0], n_int_list[1], n_int_list[2]] for _ in range(3): n_int_list.pop(0) while True: three_int = three_list[0]*100 + three_list[1]*10 + three_list[2] x = (120 + n_div_120 - (three_list[0] + three_list[1] + three_list[2]))%120 y = three_int % 120 z = (40*x + y) % 120 if z in a: a.remove(z) exchange_list_1.append(three_list[2]) for i in range(len(n_str)-3): if n_int_list[i]>=three_list[2]: n_int_list.insert(i, three_list[2]) break else: n_int_list.append(three_list[2]) three_list.pop() for i in n_int_list: if i not in exchange_list_1: three_list.append(i) n_int_list.remove(i) break else: exchange_list_1.clear() exchange_list_10.append(three_list[1]) for i in range(len(n_str)-2): if n_int_list[i]>=three_list[1]: n_int_list.insert(i, three_list[1]) break else: n_int_list.append(three_list[1]) three_list.pop() for i in n_int_list: if i not in exchange_list_10: three_list.append(i) n_int_list.remove(i) three_list.append(n_int_list[0]) n_int_list.pop(0) break else: exchange_list_10.clear() exchange_list_100.append(three_list[0]) for i in range(len(n_str)-1): if n_int_list[i]>=three_list[0]: n_int_list.insert(i, three_list[0]) break else: n_int_list.append(three_list[0]) three_list.pop() for i in n_int_list: if i not in exchange_list_100: three_list.append(i) n_int_list.remove(i) three_list.append(n_int_list[0]) n_int_list.pop(0) three_list.append(n_int_list[0]) n_int_list.pop(0) break else: print(120 - len(a)) break