#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
pair<int, int> colors[MAX];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    colors[x].first -= 1;
    colors[x].second = x;
  }
  sort(colors, colors + m + 1);
  int N = 0;
  vector<pair<int, int> > V;
  while (colors[N].first) {
    colors[N].first = -colors[N].first;
    if (N) V.push_back(colors[N]);
    ++N;
  }
  V.push_back(colors[0]);
  vector<pair<int, int> > ans;
  int j = 0, sum = 0;
  for (int i = 0; i < N; ++i) {
    while (colors[i].first && V[j].first) {
      ans.push_back(make_pair(colors[i].second, V[j].second));
      --colors[i].first;
      --V[j].first;
      if (colors[i].second != V[j].second) ++sum;
      if (!V[j].first) ++j;
    }
  }
  printf("%d\n", sum);
  for (int i = 0; i < n; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
}
