N=int(input()) P=[int(s)%10 for s in input().split()] v=[1]+[0]*9 for d in P: w=v[-d:]+v[:-d] v=[[a,max(a,b+1)][b>0] for a,b in zip(v,w)] print(v[0]-1)