#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c[5005], d[5005], i, j;
  cin >> a >> b;
  for (i = 1; i <= a; i++) {
    cin >> c[i];
    d[i] = c[i];
  }
  sort(c + 1, c + a + 1);
  sort(d + 1, d + a + 1);
  reverse(d + 1, d + a + 1);
  int ind1 = 0, ind2 = 0;
  for (i = 1; i <= a; i++) {
    if (c[i] == d[i] && ind1 == 0)
      ind1 = i;
    else if (c[i] != d[i] && ind1 != 0) {
      ind2 = i - 1;
      break;
    }
  }
  if (ind1 != 0 && ind2 == 0) ind2 = a;
  if (ind1 != 0 && ind2 != 0) {
    i = 1;
    while (ind1 <= ind2 && i < ind1) {
      if (d[i] == d[ind1] || d[i] == c[ind1] || d[ind1] == c[i]) {
        i++;
        continue;
      }
      swap(d[i], d[ind1]);
      i++;
      ind1++;
    }
    if (ind1 <= ind2) {
      i = a;
      while (ind1 <= ind2 && i > ind2) {
        if (d[i] == d[ind1] || d[i] == c[ind1] || d[ind1] == c[i]) {
          i--;
          continue;
        }
        swap(d[i], d[ind1]);
        i--;
        ind1++;
      }
    }
  }
  int ans = 0;
  for (i = 1; i <= a; i++) {
    if (c[i] != d[i]) ans++;
  }
  cout << ans << endl;
  for (i = 1; i <= a; i++) {
    cout << c[i] << " " << d[i] << endl;
  }
}
