#include <bits/stdc++.h>
using namespace std;
long h, i, k, l, m, n, t;
struct xl {
  int x = 0, ind;
  bool operator>(const xl& ob) const { return x > ob.x; }
};
int main() {
  ios_base::sync_with_stdio(false);
  vector<xl> v;
  vector<int> e;
  cin >> n >> m;
  xl ob[m + 1];
  t = n;
  for (i = 1; i <= n; i++) cin >> h, ob[h].x++, ob[h].ind = h;
  if (n == 1) {
    cout << 0 << endl << 1 << ' ' << 1;
    return 0;
  }
  for (i = 1; i <= m; i++) v.push_back(ob[i]);
  while (true) {
    sort(v.begin(), v.end(), greater<xl>());
    if (!v[0].x) break;
    if (t == 3 && v.size() > 2 && v[0].x && v[1].x && v[2].x) {
      e.push_back(v[0].ind), e.push_back(v[1].ind);
      e.push_back(v[1].ind), e.push_back(v[2].ind);
      e.push_back(v[2].ind), e.push_back(v[0].ind);
      t = 0;
      break;
    }
    if (v.size() > 1 && v[1].x) {
      e.push_back(v[0].ind), e.push_back(v[1].ind);
      e.push_back(v[1].ind), e.push_back(v[0].ind);
      v[0].x--, v[1].x--, t -= 2;
    } else
      e.push_back(v[0].ind), e.push_back(v[0].ind), v[0].x--;
  }
  cout << n - t << endl;
  for (i = 0; i < e.size(); i += 2) cout << e[i] << ' ' << e[i + 1] << endl;
  return 0;
}
