CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #965 #967 →

#966. Fewest jumps

a[i] is the largest number of steps you can jump forward from position i. Find the fewest jumps to get from the first position to the last one. If it is impossible, print -1. ### Input The first line has n, the second line has n integers separated by spaces. ### Output A number.

Examples

Input
1
0
Output
0
Input
7
1 0 0 1 1 0 0
Output
-1

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!