takes input and sorts it by value