#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int a[N], cnt[446], c[N];
int cmp(const int x, const int y) {
  if (cnt[x] != cnt[y]) return cnt[x] < cnt[y];
  return x < y;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i, max;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
    if (cnt[a[i]] > max) max = cnt[a[i]];
  }
  sort(a, a + n, cmp);
  for (i = max; i < n; i++) c[i - max] = a[i];
  for (i = 0; i < max; i++) c[n - max + i] = a[i];
  int ans = 0;
  for (i = 0; i < n; i++) ans += (a[i] != c[i]);
  printf("%d\n", ans);
  for (i = 0; i < n; i++) printf("%d %d\n", a[i], c[i]);
  return 0;
}
