#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x, y;
  int sum, lnc;
  vector<pair<int, int> > v;
} node[5010];
int n, m;
int num[5010];
int le[5010], ri[5010], cnt, sum;
int cmp(struct Node a, struct Node b) { return a.y > b.y; }
int main() {
  int sum;
  pair<int, int> p;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &num[i]);
      node[num[i]].y++;
    }
    for (int i = 1; i <= m; i++) {
      node[i].x = i;
      node[i].lnc = node[i].y;
      node[i].sum = node[i].y;
    }
    sort(node + 1, node + m + 1, cmp);
    sum = n;
    for (int i = 1, j = m;;) {
      cnt = 0;
      while (node[i].x == node[j].x || node[i].sum == 0) {
        i++;
        if (i > m) {
          i = 1;
        }
        cnt++;
        if (cnt == m) {
          break;
        }
      }
      if (cnt == m) {
        sum -= node[j].sum;
        p = make_pair(node[j].x, node[j].sum);
        node[j].v.push_back(p);
        break;
      }
      if (node[i].sum > node[j].lnc) {
        node[i].sum -= node[j].lnc;
        p = make_pair(node[i].x, node[j].lnc);
        if (node[i].x == node[j].x) {
          sum -= node[j].lnc;
        }
        node[j].lnc = 0;
        node[j].v.push_back(p);
        j--;
      } else if (node[i].sum == node[j].lnc) {
        p = make_pair(node[i].x, node[j].lnc);
        if (node[i].x == node[j].x) {
          sum -= node[j].lnc;
        }
        node[j].lnc = 0;
        node[i].sum = 0;
        node[j].v.push_back(p);
        j--;
        i++;
      } else {
        node[j].lnc -= node[i].sum;
        p = make_pair(node[i].x, node[i].sum);
        if (node[i].x == node[j].x) {
          sum -= node[j].sum;
        }
        node[i].sum = 0;
        node[j].v.push_back(p);
        i++;
      }
      if (i > m) {
        i = 1;
      }
      if (j < 1) {
        j = m;
      }
    }
    printf("%d\n", sum);
    for (int i = 1; i <= m; i++) {
      for (int j = 0; j < node[i].v.size(); j++) {
        for (int k = 0; k < node[i].v[j].second; k++) {
          printf("%d %d\n", node[i].x, node[i].v[j].first);
        }
      }
    }
  }
  return 0;
}
