#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
int a, n, m;
pair<int, int> c[100 + 10];
int t[N], revt[N], ans[N][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) c[i].second = i;
  for (int i = 0; i < n; i++) {
    cin >> a;
    c[a].first++;
  }
  sort(c + 1, c + m + 1, greater<pair<int, int> >());
  int cnt = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < c[i].first; j++) t[cnt++] = c[i].second;
  cnt = 0;
  for (int i = 2; i <= m; i++)
    for (int j = 0; j < c[i].first; j++) revt[cnt++] = c[i].second;
  for (int j = 0; j < c[1].first; j++) revt[cnt++] = c[1].second;
  int dif = 0;
  for (int i = 0; i < cnt; i++) {
    if (t[i] != revt[i]) dif++;
    ans[i][0] = t[i];
    ans[i][1] = revt[i];
  }
  cout << dif << endl;
  for (int i = 0; i < cnt; i++) cout << ans[i][0] << " " << ans[i][1] << endl;
  return 0;
}
