Creating function to find minimal value