#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long x[N + 5];
long long y[N + 5];
map<long long, bool> mark;
vector<long long> v1, v2;
vector<long long> ans;
int32_t main() {
  ios_base::sync_with_stdio(0);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> x[i];
    mark[x[i]] = 1;
    v1.push_back(x[i]);
  }
  long long res = 0, c = 1, sz = 0;
  while (sz < m) {
    for (auto it : v1) {
      if (mark[it - 1] == 0) {
        v2.push_back(it - 1);
        mark[it - 1] = 1;
      }
      if (mark[it + 1] == 0) {
        v2.push_back(it + 1);
        mark[it + 1] = 1;
      }
    }
    long long r = 0;
    for (auto it : v2) {
      if (sz < m) {
        ans.push_back(it);
        sz++;
        r++;
      }
    }
    res += (r * c);
    c++;
    v1.clear();
    v1 = v2;
    v2.clear();
  }
  cout << res << "\n";
  for (auto it : ans) {
    cout << it << " ";
  }
  return 0;
}
