n = gets.to_i
s = gets.chomp.gsub(' ', '')
a = s.split(/(?<=0)(?=0)/).map {|x| x.split(/(?<=1)(?=1)/)}.flatten.map(&:size)
if a.size < 3
    p a.inject(:+)
else
    p a.each_cons(3).map{|t| t.inject(:+)}.max
end