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

/**
 * Created by IntelliJ IDEA.
 * User: m09aya
 * Date: 18.11.2009
 * Time: 19:08:11
 * To change this template use File | Settings | File Templates.
 */
public class sortchis {
    static class Chisla implements Comparable<Chisla>{
        int a;
        int ost;
        Chisla(int o, int m){
            a=o; ost=a%m; if (ost==0) ost=m;
        }

        public int compareTo(Chisla z) {
            if (ost<z.ost) return -1;
            if (ost>z.ost) return 1;
            if ((ost==z.ost)&(a<z.a)) return -1;
            if ((ost==z.ost)&(a>z.a)) return 1;
            if ((ost==z.ost)&(a==z.a)) return 0;
            return 0;
        }

    }

    public static void main (String [] args) throws Exception {
        ArrayList q = new ArrayList<Chisla>();
        Scanner in = new Scanner(new File("numbers.in"));
        PrintWriter out = new PrintWriter (new File("numbers.out"));
        int n=0;
        int k = in.nextInt();
        while (in.hasNext()) {
            q.add( new Chisla(in.nextInt(),k) );
            n=n+1;
        }
        Collections.sort(q);
        for (int i =0; i<n; i++) {
            Chisla a = (Chisla)q.get(i);
            out.print(a.a +" ");
        }
        in.close();
        out.close();

}



}
