#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x, y;
  Node(int a = 0, int b = 0) : x(a), y(b) {}
};
struct cmp {
  bool operator()(Node a, Node b) { return a.y < b.y; }
};
int main() {
  int n, m, res = 0;
  vector<pair<int, int> > respair;
  scanf("%d %d", &n, &m);
  int colornum[105];
  memset(colornum, 0, sizeof(colornum));
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    colornum[t]++;
  }
  priority_queue<Node, vector<Node>, cmp> q;
  for (int i = 1; i < m + 1; i++)
    if (colornum[i] != 0) q.push(Node(i, colornum[i]));
  while (q.size() >= 2) {
    Node n1 = q.top();
    q.pop();
    Node n2 = q.top();
    q.pop();
    if (n1.y == 1 && n2.y == 1 && q.size() == 1) {
      q.push(n1);
      q.push(n2);
      break;
    }
    res += 2;
    respair.push_back(pair<int, int>(n1.x, n2.x));
    respair.push_back(pair<int, int>(n2.x, n1.x));
    n1.y--;
    n2.y--;
    if (n1.y > 0) q.push(n1);
    if (n2.y > 0) q.push(n2);
  }
  if (q.size() == 1) {
    Node n = q.top();
    q.pop();
    while (n.y--) {
      respair.push_back(pair<int, int>(n.x, n.x));
    }
  } else if (q.size() == 3) {
    res += 3;
    Node n1 = q.top();
    q.pop();
    Node n2 = q.top();
    q.pop();
    Node n3 = q.top();
    q.pop();
    respair.push_back(pair<int, int>(n1.x, n2.x));
    respair.push_back(pair<int, int>(n2.x, n3.x));
    respair.push_back(pair<int, int>(n3.x, n1.x));
  }
  cout << res << endl;
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", respair[i].first, respair[i].second);
  }
  return 0;
}
