from itertools import groupby N, *A = map(int, open(0).read().split()) G = [len(tuple(v)) for _, v in groupby(A)] dp = [0] * (len(G) + 2) for i, g in enumerate(G): dp[i + 2] = max(dp[i] + g, dp[i + 1] + g - 1) print(dp[-1])