#include <bits/stdc++.h>
namespace utils {
template <typename _type>
inline _type abs(const _type &a) {
  if (a < 0) return -a;
  return a;
}
template <typename _type>
inline _type sqr(const _type &a) {
  return a * a;
}
template <typename _type>
inline _type cub(const _type &a) {
  return a * a * a;
}
}  // namespace utils
using namespace std;
vector<int> freq;
struct cmp {
  inline bool operator()(const int &a, const int &b) {
    return (freq.at(a) > freq.at(b) || (freq.at(a) == freq.at(b) && a < b));
  }
};
namespace __370C__ {
const int MAX_N = 5000, MAX_M = 100;
int n, m, sol = 0;
vector<int> a;
inline void next(int &i) {
  if (++i == n) i = 0;
}
void doit(bool ok) {
  int i = 0, j = 0;
  while (j < n && a.at(i) == a.at(j)) ++j;
  if (j == n) j = 0;
  for (int foo = 1; foo <= n; ++foo, next(i), next(j)) {
    if (a.at(i) != a.at(j)) ++sol;
    if (ok) cout << a.at(i) << ' ' << a.at(j) << endl;
  }
  if (ok == false) {
    cout << sol << endl;
  }
}
void main() {
  cin >> n >> m;
  a.resize(n, 0);
  freq.resize(m + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    ++freq.at(a.at(i));
  }
  sort(a.begin(), a.end(), cmp());
  doit(false);
  doit(true);
}
}  // namespace __370C__
int main() { __370C__::main(); }
