#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  set<pair<long long, long long>> s;
  for (long long i = 0; i < n; i++) {
    if (mp[v[i] - 1] == 0) {
      mp[v[i] - 1] = 1;
      s.insert({1, v[i] - 1});
    }
    if (mp[v[i] + 1] == 0) {
      mp[v[i] + 1] = 1;
      s.insert({1, v[i] + 1});
    }
  }
  sort(v.begin(), v.end());
  vector<long long> ansv;
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    pair<long long, long long> a = *s.begin();
    s.erase(a);
    ans += a.first;
    ansv.push_back(a.second);
    if (mp[a.second - 1] == 0) {
      long long l = 0, r = n + 1;
      mp[a.second - 1] = 1;
      while (l + 1 < r) {
        long long m1 = (l + r) / 2;
        if (v[m1] < a.second - 1) {
          l = m1;
        } else {
          r = m1;
        }
      }
      if (l >= n - 1) {
        s.insert({abs(v[n - 1] - a.second + 1), a.second - 1});
      }
      s.insert({min(abs(v[l] - a.second + 1), abs(v[r] - a.second + 1)),
                a.second - 1});
    }
    if (mp[a.second + 1] == 0) {
      long long l = 0, r = n + 1;
      while (l + 1 < r) {
        long long m1 = (l + r) / 2;
        if (v[m1] < a.second + 1) {
          l = m1;
        } else {
          r = m1;
        }
      }
      if (l >= n - 1) {
        s.insert({abs(v[n - 1] - a.second - 1), a.second + 1});
      }
      s.insert({min(abs(v[l] - a.second - 1), abs(v[r] - a.second - 1)),
                a.second + 1});
      mp[a.second + 1] = 1;
    }
  }
  cout << ans << endl;
  for (long long i = 0; i < ansv.size(); i++) {
    cout << ansv[i] << " ";
  }
}
