First algorithm