#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> std[n];
  int a[m + 1];
  for (int i = 0; i < m + 1; i++) a[i] = 0;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }
  int k = 0, fir = 1;
  for (int i = 1; i < m + 1; i++) {
    for (int j = 0; j < a[i]; j++) {
      std[k].first = i;
      k++;
    }
  }
  k = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    flag = 0;
    int max = 0;
    for (int j = std[i].first + 1; j < m + 1; j++) {
      if (a[j] > a[max]) max = j;
    }
    if (max == 0) {
      for (int j = 1; j < std[i].first; j++) {
        if (a[j] > a[max]) max = j;
      }
    }
    if (max == 0) max = std[i].first;
    a[max]--;
    std[i].second = max;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (std[i].first != std[i].second) ans++;
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << std[i].first << " " << std[i].second << endl;
  }
  return 0;
}
