N=int(input()) A=list(map(int,input().split())) A.append("?") NOW=-1 count=0 LIST=[] for a in A: if NOW==a: count+=1 else: LIST.append((NOW,count)) NOW=a count=1 DP=[0]*len(LIST) for i in range(1,len(LIST)): DP[i]=max(DP[i-1],DP[i-1]-1+LIST[i][1],DP[i-2]+LIST[i][1]) print(max(DP))