#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, int> mym;
void kaisa() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    mym[x] = 0;
    q.push(x);
  }
  long long res = 0;
  vector<int> ans;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (mym[x] != 0) {
      res += mym[x];
      ans.push_back(x);
      if (ans.size() == m) break;
    }
    if (!mym.count(x + 1)) {
      mym[x + 1] = mym[x] + 1;
      q.push(x + 1);
    }
    if (!mym.count(x - 1)) {
      mym[x - 1] = mym[x] + 1;
      q.push(x - 1);
    }
  }
  cout << res << "\n";
  for (int i : ans) {
    cout << i << " ";
  }
  cout << "\n";
}
int main() {
  kaisa();
  return 0;
}
