I need an algorithm