n = int(input()) A = list(map(int,input().split())) #i番目を採用しない→dp[i][0],する→dp[i][1] #それぞれの最大値 dp = [[0]*2 for _ in range(n)] dp[0][1] = 1 for i in range(1,n): if A[i-1] == A[i]: dp[i][1] = max(dp[i-1][1]+1, dp[i-1][0]) dp[i][0] = max(dp[i-1][0], dp[i-1][1]) else: dp[i][1] = max(dp[i-1][0]+1, dp[i-1][0]) dp[i][0] = max(dp[i-1][0], dp[i-1][1]) print(max(dp[n-1][0], dp[n-1][1]))