Solution to the second exercise