from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) N = inp() AA = inpl() tmpl = [] ba = -1 for a in AA: if ba == a: tmpl[-1] += 1 else: tmpl.append(1) ba = a L = len(tmpl) # print(tmpl) DP = [0]*L if L == 1: print(tmpl[0]) sys.exit() elif L == 2: print(sum(tmpl)-1) sys.exit() for i,x in enumerate(tmpl): if i == 0: DP[i] = x else: DP[i] = max(DP[i-1] + x-1, DP[i-2] + x + max(0,tmpl[i-1]-2)) # print(DP) print(DP[-1])