#include <bits/stdc++.h>
using namespace std;
int a[5001], d[101];
pair<int, int> p[5001];
int main() {
  int n, m, i, j, k, res = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i) {
    scanf("%d", a + i);
    ++d[a[i]];
    p[i].first = p[i].second = a[i];
  }
  for (i = 1; i <= m; ++i) {
    if (d[i] > n / 2) res = 2 * d[i] - n;
  }
  printf("%d\n", n - res);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      if (i == j) continue;
      if (p[i].first != p[i].second) continue;
      if (p[j].first != p[i].first && p[j].second != p[i].first &&
          p[j].second != p[j].first) {
        k = p[i].first;
        p[i].first = p[j].first;
        p[j].first = k;
        break;
      } else if (p[j].first != p[i].first && p[j].first == p[j].second) {
        k = p[i].first;
        p[i].first = p[j].first;
        p[j].first = k;
        break;
      }
    }
  }
  for (i = 0; i < n; ++i) printf("%d %d\n", p[i].first, p[i].second);
  return 0;
}
