#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> t(n);
  map<int, bool> vis;
  vector<int> ans;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    vis[t[i]] = 1;
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  for (int i = 0; i < n; i++) {
    q.push({1, t[i] + 1}), q.push({1, t[i] - 1});
  }
  sort(t.begin(), t.end());
  while (m) {
    auto x = q.top();
    q.pop();
    if (vis[x.second]) continue;
    m--;
    vis[x.second] = 1;
    sum += x.first;
    ans.push_back(x.second);
    int cur = x.second;
    for (auto nx : {cur - 1, cur + 1}) {
      if (vis[nx]) continue;
      auto it = lower_bound(t.begin(), t.end(), nx);
      int mn = 2e9 + 1;
      if (it == t.end()) {
        mn = min(mn, nx - t.back());
      } else {
        mn = min(mn, abs(nx - *it));
        if (it != t.begin()) {
          it--;
          mn = min(mn, abs(nx - *it));
        }
      }
      q.push({mn, nx});
    }
  }
  cout << sum << "\n";
  for (auto x : ans) cout << x << " ";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
