import sys sys.setrecursionlimit(10**7) def g(n,p): if p==N: cnt=0 while n%2==0: cnt+=1 n//=2 return cnt num=p c=b.copy() for i in str(n): c[int(i)-1]-=1 for k in range(9): if c[k]>0 and (n+(k+1)*pow(10,p))%pow(2,p+1)==0: num=max(num,g(n+(k+1)*10**p,p+1)) return num N=int(input()) b=list(map(int,input().split())) print(g(0,0))