Sort based on the shortest match