#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, m, a[5005], b[5005], cnt[105];
void solve() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  vector<pair<int, int> > v;
  for (int i = 1; i <= m; i++) {
    v.push_back(make_pair(cnt[i], i));
  }
  sort(v.begin(), v.end());
  int ptr = 0;
  for (size_t i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].first; j++) {
      a[ptr++] = v[i].second;
    }
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[n - i - 1];
  }
  int tl = n, tr = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      tl = min(tl, i);
      tr = max(tr, i);
    }
  }
  int l = 0, r = n - 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      if (tr < r && b[i] != b[r]) {
        swap(b[i], b[r]);
        r--;
      } else if (l < tl && b[i] != b[l]) {
        swap(b[i], b[l]);
        l++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ' << b[i] << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    solve();
  }
}
