Implementation of first problem