How to Untangle Necklaces?