import java.io.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable{
    public class Fig implements Comparable<Fig>{
        int f;
        int k;
        Fig(int x, int y){
            f = x;
            k = y;
        }
        public int compareTo(Fig p){
            if(p.k == -1) return -1;
            int f1 = f%k;
            if(f1==0) f1 = k;
            int p1 = p.f%k;
            if(p1==0) p1 = k;
            if(f1 > p1) return 1;
            if(f1 < p1) return -1;
            if(f1 == p1){
                if(f > p.f) return 1;
                if(f < p.f) return -1;
            }
            return 0;
        }

    }
    public static void main(String[] args){
        new Thread (new Main()).start();
    }


    public void run(){
                try{
                    Scanner s = new Scanner(new File("numbers.in"));
                    PrintWriter p = new PrintWriter(new File("numbers.out"));
                    int k = s.nextInt();

                    Fig[] a = new Fig[100001];

                    for(int i = 0; i < 100001; i++){
                        a[i] = new Fig(0,-1);
                    }

                    int i = 0;

                    while(s.hasNext()){
                        int b = s.nextInt();
                        a[i++] = new Fig(b,k);
                    }

                    Arrays.sort(a);

                    for(int j = 0; j < i; j++){

                        p.print(a[j].f + " ");
                    }
                    p.println();
                    p.close();

                } catch(Exception e){
                    e.printStackTrace();
                    System.exit(1);
                }
    }

}