Solution to the first problem