/**
 * Created by IntelliJ IDEA.
 * User: o_215
 * Date: 18.11.2009
 * Time: 18:29:33
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import java.io.*;

class B {
    static class Point implements Comparable<Point> {
        int kMod; int num;
        public Point(int _x,int _y){kMod=_x;num=_y;}
        public int compareTo(Point p) {
            return (kMod-p.kMod!=0)?kMod-p.kMod:num-p.num;
        }
    }
    public static void main(String[] args) throws Exception{
        Scanner in=new Scanner(new File("numbers.in"));
        PrintWriter out=new PrintWriter(new File("numbers.out"));
        Point[] p=new Point[100000];
        int k=in.nextInt();
        int i=0;
        while (in.hasNext()){
            int num=in.nextInt();
            p[i]=new Point((num%k==0)?k:num%k,num);
            i++;
        }
        Arrays.sort(p,0,i);
        for(int j=0;j<i;j++){
            out.print(p[j].num+" ");
        }
        in.close();
        out.close();
    }

}
