#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<int> v(2 * n);
  vector<int> col(m + 1);
  for (int i = 0; i < n; i++) {
    cin >> k;
    col[k]++;
  }
  int max = 0, maxindex = 0, q = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (col[j] > max) {
        max = col[j];
        maxindex = j;
      }
    }
    for (int e = 0; e < 2 * max; e++) v[q + e] = maxindex;
    q += (2 * max);
    max = -1;
    col[maxindex] = -1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] != v[i + n]) ans++;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      cout << v[i] << " " << v[i + n] << endl;
    else
      cout << v[i + n] << " " << v[i] << endl;
  }
  return 0;
}
