import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.io.File;
import java.io.PrintWriter;

/**
 * Created by IntelliJ IDEA.
 * User: m09dam
 * Date: 18.11.2009
 * Time: 18:54:20
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import java.io.*;
public class problem_B_18_11_09 {
    static class Pair implements Comparable<Pair>{
                 int x;
                 int y;
                 Pair(int a, int b){
                     x = a;
                     y = b;
                 }
            public int compareTo(Pair p){
                if (x!=p.x) {return x-p.x;}
                else {return y-p.y;}
            }
        }


    public static void main (String[] args)throws Exception{
         Scanner in = new Scanner( new File ("numbers.in"));
         PrintWriter out = new PrintWriter ( new File ("numbers.out"));
         int c = in.nextInt();

         ArrayList<Pair> p = new ArrayList<Pair>();
         while (in.hasNext()){
             int b = in.nextInt();
             int a = b%c;
             p.add(new Pair(a,b));
         }
        Collections.sort(p);
        int k=0;
        for(int i = 0; i < p.size();i++){
            if (p.get(i).x==0){k++;}
            else{out.print(p.get(i).y+" ");}
        }
        for(int i = 0; i < p.size();i++){
            if (p.get(i).x==0){out.print(p.get(i).y+" ");}
        }
        out.close();
        in.close();
      }

}
