Implemented algorithmic task #2