Finding a minimum number between n number of pairs (x,y)