
import java.util.*;
import java.io.*;

class Numbers implements Runnable{

    class Num implements Comparable<Num> {
        int value, rq;

        Num(int v, int k){
          value = v;
          int tmp = value % k;
          if(tmp == 0)
            rq = k + 1;
          else
            rq = tmp;
        }

        public int compareTo(Num  n){
         if(rq < n.rq)
              return -1;
           else if(rq > n.rq)
                   return 1;
           else{
              if(value < n.value)
                return -1;
              else if(value > n.value)
                     return 1;
                   else return 0;
           }
        }
    }
     public void run(){
       try{
           Scanner in = new Scanner(new File("numbers.in"));
           PrintWriter out = new PrintWriter(new File("numbers.out"));

           int k = in.nextInt();

           ArrayList<Num> nm = new ArrayList<Num>();
           int n = 0;
           while(in.hasNextInt()) {
              nm.add(new Num(in.nextInt(), k));
              n++;
           }

           Collections.sort(nm);
           for(int i = 0; i < n; i++){
               out.print(nm.get(i).value);
               out.print(" ");
           }
           out.println();

           in.close();
           out.close();
       }  catch(Exception e){
            e.printStackTrace();
            System.exit(1);
          }
     }
     public static void main(String[] args) {
        new Thread(new Numbers()).start();
     }
}
