#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m;
  vector<int> count(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> x;
    count[x - 1]++;
  }
  vector<pair<int, int> > pcount;
  for (int i = 0; i < m; i++) {
    pcount.push_back(make_pair(count[i], i + 1));
  }
  sort(pcount.begin(), pcount.end());
  reverse(pcount.begin(), pcount.end());
  vector<int> lefthand, righthand;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < pcount[i].first; j++) {
      lefthand.push_back(pcount[i].second);
    }
  }
  for (int i = 0; i < n; i++) {
    righthand.push_back(lefthand[(i + pcount[0].first) % n]);
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (lefthand[i] != righthand[i]) res++;
  }
  cout << res << endl;
  for (int i = 0; i < n; i++) {
    cout << lefthand[i] << " " << righthand[i] << endl;
  }
  return 0;
}
