N = int(input()) lsA = list(map(int,input().split())) dp = [[0,0] for i in range(N)] dp[0][1] = 1 for i in range(1,N): if lsA[i] == lsA[i-1]: dp[i][1] = max(dp[i-1][1]+1,dp[i-1][0]) dp[i][0] = max(dp[i-1][1],dp[i-1][0]) else: dp[i][1] = max(dp[i-1][0]+1,dp[i-1][0]) dp[i][0] = max(dp[i-1][1],dp[i-1][0]) print(max(dp[N-1]))