#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> chris(n), t1, t2, fin;
  set<long long> s1;
  long long i, j;
  for (i = 0; i < n; ++i) {
    cin >> chris[i];
    s1.insert(chris[i]);
  }
  t1 = chris;
  long long diff = 0, count = 0;
  for (i = 0; i < m + 1;) {
    ++diff;
    for (j = 0; j < t1.size(); ++j) {
      long long temp1 = t1[j] - 1;
      long long temp2 = t1[j] + 1;
      if (s1.find(temp1) == s1.end()) {
        ++i;
        if (i > m) break;
        s1.insert(temp1);
        t2.push_back(temp1);
        fin.push_back(temp1);
        count += diff;
      }
      if (s1.find(temp2) == s1.end()) {
        ++i;
        if (i > m) break;
        s1.insert(temp2);
        t2.push_back(temp2);
        fin.push_back(temp2);
        count += diff;
      }
    }
    t1 = t2;
    t2.clear();
  }
  cout << count << "\n";
  for (i = 0; i < fin.size(); ++i) {
    cout << fin[i] << " ";
  }
}
