The shortest way out of a maze