Solution to first problem