#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
  istringstream sin(s);
  int t;
  sin >> t;
  return t;
}
template <class T>
string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
long long toInt64(string s) {
  istringstream sin(s);
  long long t;
  sin >> t;
  return t;
}
template <class T>
T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
long long C(long long n, long long m) {
  long long a[100], b[100];
  if (n < m) return 0;
  if (m == 0) return 1;
  if (m == 1) return n;
  for (int i = 1; i <= m; i++) {
    a[i] = n - i + 1;
    b[i] = i;
  }
  long long ans = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      long long s = gcd(a[i], b[j]);
      if (s > 1) {
        a[i] /= s;
        b[j] /= s;
      }
    }
    ans *= a[i];
  }
  return ans;
}
int a[50005], b[50005];
struct node {
  int x;
  int l, r;
} d[150];
bool cmp(const node& c, const node& p) { return c.l > p.l; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    d[i].l = d[i].r = 0;
    d[i].x = -1;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    d[x].x = x;
    d[x].l++;
    d[x].r++;
  }
  sort(d + 1, d + m + 1, cmp);
  int k = 0;
  for (int i = 1; i <= m; i++) {
    if (d[i].l == 0) continue;
    for (int j = 1; j <= m; j++) {
      if (i == j) continue;
      while (d[j].r && d[i].l) {
        d[j].r--;
        d[i].l--;
        a[k] = d[i].x;
        b[k] = d[j].x;
        k++;
      }
    }
  }
  int q = k;
  int r[105];
  (memset(r, (0), sizeof(r)));
  for (int i = 1; i <= m; i++)
    if (d[i].l) {
      for (int j = 0; j < k; j++)
        if (a[j] != d[i].x && b[j] != d[i].x) {
          int temp = b[j];
          b[j] = d[i].x;
          a[q] = d[i].x;
          b[q] = temp;
          q++;
          d[i].l--;
          if (d[i].l == 0) break;
        }
    }
  k = q;
  cout << k << endl;
  for (int i = 0; i < k; i++) cout << a[i] << " " << b[i] << endl;
  for (int i = 1; i <= m; i++)
    if (d[i].l) {
      for (int j = 1; j <= m && d[i].l; j++)
        while (d[j].r) {
          cout << d[i].x << " " << d[j].x << endl;
          d[j].r--;
          d[i].l--;
        }
    }
  return 0;
}
