#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
vector<int> hole[N];
int cnt[N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int c;
    cin >> c;
    cnt[c]++;
  }
  vector<pair<int, int> > x;
  for (int i = 1; i <= m; i++) x.push_back({cnt[i], i});
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());
  int nn = x.begin()->first;
  int now = 0;
  for (int i = 1; i < x.size(); i++) {
    for (int j = 0; j < x[i].first; j++)
      hole[now].push_back(x[i].second), now = (now + 1) % nn;
  }
  vector<int> a;
  for (int i = 0; i < nn; i++) {
    a.push_back(x.begin()->second);
    for (int j : hole[i]) a.push_back(j);
  }
  int ans = 0;
  assert(n == a.size());
  for (int i = 0; i < n; i++) ans += a[i] != (a[(i + 1) % n]);
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    cout << a[i] << " " << a[(i + 1) % n] << "\n";
  }
}
