Solution to the required task