def tanku?(a)
    c = 0
    l = 0
    s = [5, 7, 5, 7, 7]
    a.each do |k|
        return false if c > 4
        l += k
        if l >= s[c]
            return false if l != s[c]
            c += 1
            l = 0
        end
    end
    return l == 0 && c == 5
end

loop do
    n = gets.to_i
    break if n == 0
    a = []
    l = 0
    ans = nil
    n.times do |i|
        a << gets.size - 1
        next if ans
        l += a[-1]
        l -= a.shift until l <= 31
        if l == 31 && tanku?(a)
            ans = i - a.size + 2
        end
    end
    puts ans
end
