Solves problem 1