#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> colors[101];
int left_mitten[5001], right_mitten[5001];
void sort_colors() {
  sort(colors, colors + m + 1, [](const vector<int> &a, const vector<int> &b) {
    return a.size() > b.size();
  });
}
int main() {
  cin >> n >> m;
  for (int i = 0; i <= m; i++) {
    colors[i] = vector<int>({i});
  }
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    colors[c].push_back(i);
    left_mitten[i] = c;
    right_mitten[i] = c;
  }
  int r = 0;
  int r2 = 0;
  while (true) {
    sort_colors();
    if (colors[0].size() == 2 && colors[1].size() == 1) {
      int c = colors[0][0];
      int child = colors[0][1];
      for (int i = 0; i < n; i++) {
        if (left_mitten[i] != c && right_mitten[i] != c) {
          int tmp = right_mitten[i];
          right_mitten[i] = right_mitten[child];
          right_mitten[child] = tmp;
          r2++;
          break;
        }
      }
    }
    if (colors[0].size() < 2 || colors[1].size() < 2) break;
    r++;
    int c1 = colors[0].back(), c2 = colors[1].back();
    right_mitten[c1] = colors[1][0];
    right_mitten[c2] = colors[0][0];
    colors[0].pop_back();
    colors[1].pop_back();
  }
  cout << r * 2 + r2 << endl;
  for (int i = 0; i < n; i++) {
    cout << left_mitten[i] << " " << right_mitten[i] << endl;
  }
}
