import java.util.*;

public class Min
{
  /**
     * @param V : a vector of Integer values
     * @param nb : the number of required minimum values
     * @return : the vector composed of nb minimum values from V if possible (null otherwise)
     */

  public static Vector f(Vector V, int nb)
  {
      if( (V == null) )
          return null;
      
      int k = ((V.size() < nb) ? V.size() : nb);  // avoid incoherent values
      int i = 0;
      int j;
      Vector R = new Vector();

      while( i < k )
          {
              R.addElement(V.elementAt(i));
              i++;
          }

      Collections c = null;
      Integer max_R = null;
      Integer cur_V = null;

      while( i < V.size() ) 
          {
              j = 0;
              while( j < k )  // k is the size of R
                  {
                      max_R = (Integer) c.max(R) ;   // max value of R
                      cur_V = (Integer) V.elementAt(i);  // current value of V
              
                      if( max_R.intValue() != cur_V.intValue() )  // != au lieu de >
                          {
                              R.setElementAt(cur_V , R.indexOf(max_R));
                              break;
                          }
                      j++;
                  }
              i++;
          }
 
      return(R);
  }


   public static void main(String argv[])
     {    
       Vector A = new Vector(10);
       A.addElement(new Integer(5));
       A.addElement(new Integer(54));
       A.addElement(new Integer(78));
       A.addElement(new Integer(10));
       A.addElement(new Integer(199));
       A.addElement(new Integer(22));
       A.addElement(new Integer(22));
       A.addElement(new Integer(9));
       A.addElement(new Integer(3));
       A.addElement(new Integer(9));

       Vector r = f(A,6);

       System.out.println(r);
     }
}
    

