#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
const int maxm = 1010;
const int inf = 1e8;
const int mod = 1e9 + 7;
int n, m;
struct Child {
  int l;
  int r;
} cd[maxn];
int cnt[maxn];
int main() {
  int i, j;
  int k;
  scanf("%d%d", &n, &m);
  memset(cnt, 0, sizeof(cnt));
  for (i = 1; i <= n; i++) {
    int temp;
    scanf("%d", &temp);
    cnt[temp]++;
  }
  int num = 1;
  for (i = 1; i <= m; i++) {
    if (cnt[i] == 0) continue;
    for (j = 1; j <= m; j++) {
      if (j == i || cnt[j] == 0) continue;
      while (cnt[i] > 0 && cnt[j] > 0) {
        cd[num].l = i;
        cd[num++].r = j;
        cd[num].l = j;
        cd[num++].r = i;
        cnt[i]--;
        cnt[j]--;
      }
      if (cnt[i] == 0) break;
    }
  }
  int flag = 0;
  for (i = 1; i <= m; i++) {
    if (cnt[i] != 0) {
      flag = i;
      break;
    }
  }
  if (flag) {
    for (i = 1; i < num; i++) {
      if (cd[i].l == flag || cd[i].r == flag) continue;
      cd[num].l = cd[i].l;
      cd[num++].r = flag;
      cd[i].l = flag;
      cnt[flag]--;
      if (cnt[flag] == 0) break;
    }
  }
  printf("%d\n", num - 1);
  for (i = 1; i < num; i++) {
    printf("%d %d\n", cd[i].l, cd[i].r);
  }
  for (i = 1; i <= (n - num) + 1; i++) {
    printf("%d %d\n", flag, flag);
  }
  return 0;
}
