#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
set<pair<int, int> > s;
map<int, bool> bio;
long long ans;
vector<int> sol;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    s.insert({1, x - 1});
    s.insert({1, x + 1});
    bio[x] = true;
  }
  while (m > 0) {
    while (true) {
      if (s.size() == 0) break;
      if (bio[s.begin()->second] == true) {
        s.erase(s.begin());
      } else {
        break;
      }
    }
    ans += (long long)s.begin()->first;
    sol.push_back(s.begin()->second);
    bio[s.begin()->second] = true;
    if (!bio[s.begin()->second + 1])
      s.insert({s.begin()->first + 1, s.begin()->second + 1});
    if (!bio[s.begin()->second - 1])
      s.insert({s.begin()->first + 1, s.begin()->second - 1});
    s.erase(s.begin());
    m--;
  }
  printf("%lld\n", ans);
  for (auto it : sol) printf("%d ", it);
  printf("\n");
  return 0;
}
