We use the function next several times:
next 6
3
next 3
10
next 10
5
next 5
16
next 16
8
next 8
4
next 4
2
next 2
1
The answer is 9 numbers.