#include <bits/stdc++.h>
using namespace std;
const int maxN = 5005;
int c[maxN], ans, n, m, mxsz;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(c, c + n);
  for (int i = 0; i < n; i++) {
    int sz = 1;
    for (; i + 1 < n && c[i] == c[i + 1]; i++) sz++;
    mxsz = max(mxsz, sz);
  }
  for (int i = 0; i < n; i++)
    if (c[i] != c[(i + mxsz) % n]) ans++;
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << c[i] << " " << c[(i + mxsz) % n] << endl;
  return 0;
}
