Learn how to implement and use the floodfill algorithm in Python.
Grab a piece of paper and try to fold your way out of this problem.