#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
int n, m;
int L[N], R[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) {
    cin >> L[i];
    R[i] = L[i];
  }
  sort(L, L + n);
  sort(R, R + n);
  int cur = 1, curmax = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (L[i] != L[i - 1]) {
      curmax = max(curmax, cur);
      cur = 1;
    } else
      cur++;
  }
  curmax = max(curmax, cur);
  {
    cerr << ">>> "
         << "curmax"
         << " : " << curmax << endl;
  };
  int ans = 0;
  for (int i = 0; i <= n - 1; i++) ans += L[i] != R[(i + curmax) % n];
  cout << ans << endl;
  for (int i = 0; i <= n - 1; i++)
    cout << L[i] << ' ' << R[(i + curmax) % n] << '\n';
  return 0;
}
