#include <bits/stdc++.h>
using namespace std;
int const dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int const dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int64_t const LIM = 1e6, INF = 1e9, MOD = 1e9 + 7;
double const PI = 3.141592653589793, EPS = 1e-7;
int n, m, c[LIM], mt[LIM], colors[LIM];
bool used[LIM];
vector<int> g[LIM];
bool try_khun(int u) {
  if (used[u]) return false;
  used[u] = true;
  for (auto v : g[u]) {
    if (mt[v] == -1 || try_khun(mt[v])) {
      mt[v] = u;
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  double t = double(clock()) / CLOCKS_PER_SEC;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    --c[i];
    colors[c[i]] += 2;
  }
  random_shuffle(c, c + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (c[i] != c[j]) g[i].push_back(j);
    }
  }
  fill(mt, mt + n, -1);
  vector<bool> used1(n, false);
  for (int i = 0; i < n; ++i) {
    if (rand() & 1) continue;
    for (size_t j = 0; j < g[i].size(); ++j)
      if (mt[g[i][j]] == -1) {
        mt[g[i][j]] = i;
        used1[i] = true;
        break;
      }
  }
  for (int i = 0; i < n; ++i)
    if (!used1[i])
      for (size_t j = 0; j < g[i].size(); ++j)
        if (mt[g[i][j]] == -1) {
          mt[g[i][j]] = i;
          used1[i] = true;
          break;
        }
  for (int i = 0; i < n; i++) {
    if (used1[i]) continue;
    fill(used, used + n, false);
    try_khun(i);
    if (double(clock()) / CLOCKS_PER_SEC - t >= 0.7) break;
  }
  vector<pair<int, int>> ans;
  for (int i = 0; i < n; i++) {
    if (mt[i] != -1) {
      ans.push_back(make_pair(c[mt[i]], c[i]));
      --colors[c[mt[i]]];
      --colors[c[i]];
    }
  }
  cout << ans.size() << '\n';
  cout.flush();
  for (int i = 0; i < m; i++) {
    if (colors[i] % 2 != 0) assert(false);
    while (colors[i] > 0) {
      ans.push_back(make_pair(i, i));
      colors[i] -= 2;
    }
  }
  for (auto x : ans) cout << x.first + 1 << ' ' << x.second + 1 << '\n';
  return 0;
}
