#include <bits/stdc++.h>
using namespace std;
long long n, m, t;
long long num[100005];
long long ok = false;
void solve() {
  long long m;
  cin >> n >> m;
  deque<long long> v;
  v.clear();
  v.resize(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  map<long long, bool> M;
  map<long long, long long> Ml;
  map<long long, long long> Mr;
  set<long long> left;
  for (auto k : v) {
    left.insert(k);
    M[k] = 1;
    Ml[k] = k - 1;
    Mr[k] = k + 1;
  }
  long long ctr = 0;
  deque<long long> ans;
  long long sum = 0;
  vector<long long> toer;
  while (m > 0) {
    for (auto k : toer) {
      left.erase(left.find(k));
    }
    toer.clear();
    for (auto k : left) {
      long long flag = 0;
      if (M[Ml[k]]) {
        flag++;
      } else {
        m--;
        ans.push_back(Ml[k]);
        sum += abs(k - Ml[k]);
        M[Ml[k]] = 1;
        Ml[k]--;
        if (m == 0) break;
      }
      if (M[Mr[k]]) {
        flag++;
      } else {
        m--;
        ans.push_back(Mr[k]);
        sum += abs(k - Mr[k]);
        M[Mr[k]] = 1;
        Mr[k]++;
        if (m == 0) break;
      }
      if (flag == 2) {
        toer.push_back(k);
      }
    }
  }
  cout << sum << endl;
  for (auto k : ans) {
    cout << k << " ";
  }
  cout << endl;
}
int32_t main() {
  cin.tie(0);
  ios_base::sync_with_stdio(NULL);
  t = 1;
  while (t--) solve();
  return 0;
}
