#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long ans = 0;
  queue<long long> q;
  map<int, long long> mp;
  for (auto x : v) {
    mp[x] = 0;
    q.push(x);
  }
  vector<long long> res;
  while (!q.empty()) {
    long long top = q.front();
    q.pop();
    if (mp[top] != 0) {
      ans += mp[top];
      res.push_back(top);
      if (res.size() == k) {
        break;
      }
    }
    if (!mp.count(top - 1)) {
      mp[top - 1] = mp[top] + 1;
      q.push(top - 1);
    }
    if (!mp.count(top + 1)) {
      mp[top + 1] = mp[top] + 1;
      q.push(top + 1);
    }
  }
  cout << ans << endl;
  for (auto x : res) {
    cout << x << " ";
  }
}
