#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long add(long long a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
void solve() {
  long long n, m, sum = 0, l, r;
  cin >> n >> m;
  vector<long long> v(n), ans;
  for (long long i = (0); i < (n); ++i) cin >> v[i];
  sort((v).begin(), (v).end());
  set<pair<long long, long long> > man;
  l = v[0] - 1;
  for (long long i = (1); i < (n); ++i) man.insert({v[i - 1] + 1, v[i] - 1});
  r = v[n - 1] + 1;
  long long mm = m, cnt = 1, wow = 10;
  while (mm > 0) {
    auto it = man.begin();
    ans.push_back(l--);
    sum += cnt;
    mm--;
    if (!mm) break;
    set<pair<long long, long long> > nman;
    while (it != man.end()) {
      if (it->first > it->second)
        ;
      else if (it->first == it->second) {
        ans.push_back(it->first);
        mm--;
        sum += cnt;
        if (!mm) break;
      } else {
        ans.push_back(it->first);
        ans.push_back(it->second);
        nman.insert({it->first + 1, it->second - 1});
        mm--;
        sum += cnt;
        if (!mm) break;
        mm--;
        sum += cnt;
        if (!mm) break;
      }
      it++;
    }
    if (!mm) break;
    ans.push_back(r++);
    sum += cnt;
    mm--;
    man = nman;
    cnt++;
  }
  cout << sum << "\n";
  for (long long i = (0); i < (m); ++i) cout << ans[i] << " ";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  for (long long i = 1; i <= tt; i++) solve();
}
