public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        HashMap<Integer, Integer> colorNum = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            int color = sc.nextInt();
            if (!colorNum.containsKey(color)) {
                colorNum.put(color, 0);
            }
            colorNum.put(color, colorNum.get(color)+1);
        }
        
        ArrayList<Mitten> mittens = new ArrayList<Mitten>();
        
        for (Map.Entry<Integer, Integer> entry: colorNum.entrySet()) {
            mittens.add(new Mitten(entry.getKey(), entry.getValue()));
        }
        
        Collections.sort(mittens);
        
        int n_max = mittens.get(0).number;
        int c_max = mittens.get(0).color;
        int n_t = 0;
        for (int i = 1; i < mittens.size(); i++) {
            n_t = n_t + mittens.get(i).number;
        }
        
        if (n_max >= n_t) {
            System.out.printf("%d\n", 2 * n_t);
            pairMittens(mittens);
            for (int i = 0; i < (n_max - n_t); i++) {
                System.out.printf("%d %d\n", c_max, c_max);
            }
            return;
        }
        
        System.out.printf("%d\n", n_max + n_t);
        int sz = mittens.size() - 1;
        while (n_t > n_max && n_t - n_max >= sz - 1) {
            cascade(mittens);
            n_max--;
            n_t -= sz;
            sz = mittens.size() - 1;
        }
        if (n_t > n_max) {
            int t = n_t - n_max + 1;
            cascade(mittens, t);
        }
        pairMittens(mittens);
    }