Solving first part of problem 4.