Solving first part of problem 1.