#include <bits/stdc++.h>
using namespace std;
template <typename T>
void operator<<(ostream& c, vector<T>& a) {
  for (T el : a) {
    c << el << ' ';
  }
  cout << '\n';
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> trees(n);
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> trees[i];
  }
  sort(trees.begin(), trees.end());
  set<int> left, right;
  for (int i = 0; i < n; ++i) {
    left.insert(i);
    right.insert(i);
  }
  vector<int> ans;
  for (int r = 1; m != 0; ++r) {
    auto it = left.begin();
    for (; it != left.end();) {
      int tree = *it;
      if (tree == 0 || trees[tree] - trees[tree - 1] - 1 >= 2 * r) {
        res += r;
        ans.push_back(trees[tree] - r);
        --m;
        if (m == 0) {
          break;
        }
        ++it;
      } else {
        auto it2 = it;
        ++it;
        left.erase(it2);
      }
    }
    if (m == 0) {
      break;
    }
    it = right.begin();
    for (; it != right.end();) {
      int tree = *it;
      if (tree == n - 1 || trees[tree + 1] - trees[tree] - 1 >= 2 * r - 1) {
        res += r;
        ans.push_back(trees[tree] + r);
        --m;
        if (m == 0) {
          break;
        }
        ++it;
      } else {
        auto it2 = it;
        ++it;
        right.erase(it2);
      }
    }
  }
  cout << res << '\n' << ans;
  return 0;
}
