def sol d, s f = 'x' c = 0 a = [] 15.times{|i| if s[i] == f c += 1 else a.push(c) f = s[i] c = 1 end } a.push(c) if a.size == 1 return d else a.pop a.shift ans = [a[0] + d, a[-1] + d].max a.size.times{|i| if i % 2 == 0 next end if a[i] > d ans = [ans, a[i - 1] + d, a[i + 1] + d].max else ans = [ans, a[i - 1] + a[i] + a[i + 1]].max end } return ans end end d = gets.to_i s = STDIN.map(&:chomp).join('') s += 'x' p sol(d, s)