How to find smallest and largest fraction