------
## 最终结论
```python
def numTimesAllBlue(light):
    rightmost = 0
    moments = 0
    
    for i, bulb in enumerate(light):
        rightmost = max(rightmost, bulb)
        if rightmost == i + 1:
            moments += 1
    
    return moments

# Example usage:
# light = [2,1,3,5,4]
# print(numTimesAllBlue(light)) # Output: 3
```