#define _USE_MATH_DEFINES

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define SREP(s,i,n) for(int i=s;i<(int)(n);++i)
#define REP(i,a) SREP(0,i,a)
#define ALL(a) (a).begin(),(a).end()

#define CLR(a) memset(a,0,sizeof(a))
#define REMOVE_AT(v,i) v.erase(v.begin()+i)

using namespace std;
const double EPS = 1e-8;
const double D_INF = 1e12;
const int I_INF = 1 << 29;
typedef long long LL;

#ifdef __GNUC__
#define mie_bsf(pindex, val) \
    val ? *pindex = __builtin_ctz(val), 1 : 0
#define mie_bsf64(pindex, val) \
    val ? *pindex = __builtin_ctzl(val), 1 : 0

#define mie_bsr(pindex, val) \
        val ? (*pindex = __builtin_clz(val) ^ 0x1f), 1 : 0
#define mie_bsr64(pindex, val) \
        val ? (*pindex = __builtin_clzl(val) ^ 0x3f), 1 : 0

#elif _MSC_VER

#include<intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt64

#define mie_bsf(pindex, val) _BitScanForward( \
    reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsf64(pindex, val) _BitScanForward64( \
    reinterpret_cast<unsigned long *>(pindex), val)

#define mie_bsr(pindex, val) _BitScanReverse( \
        reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsr64(pindex, val) _BitScanReverse64( \
        reinterpret_cast<unsigned long *>(pindex), val)

#endif

int main(){
    int sum, limit;
    scanf("%d%d", &sum, &limit);
    vector<int> res;
    if (sum <= limit)
    {
        for (int i = 1; i <= sum; i <<= 1)
        {
            if ((i & sum) != 0)
            {
                res.push_back(i);
            }
        }
    }
    else
    {
        int s = 0;
        vector<vector<int> > bits(32);
        for (int i = 1; i <= limit; i++)
        {
            int out;
            mie_bsf(&out, i);
            s += out + 1;
            bits[out].push_back(i);
        }
        if (s < sum)
        {
            printf("-1\n");
            return 0;
        }
        while (sum > 0)
        {
            int bit;
            mie_bsr(&bit, sum);
            for (int i = bit; i >= 0; i--)
            {
                if (bits[i].size() > 0)
                {
                    res.push_back(*bits[i].rbegin());
                    bits[i].pop_back();
                    sum -= i + 1;
                    break;
                }
            }
        }
    }
    printf("%d\n", res.size());
    for (int i = 0; i < res.size(); i++)
    {
        printf("%d%c", res[i], i + 1 < res.size() ? ' ' : '\n');
    }
    return 0;
}


#define _USE_MATH_DEFINES

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define SREP(s,i,n) for(int i=s;i<(int)(n);++i)
#define REP(i,a) SREP(0,i,a)
#define ALL(a) (a).begin(),(a).end()

#define CLR(a) memset(a,0,sizeof(a))
#define REMOVE_AT(v,i) v.erase(v.begin()+i)

using namespace std;
const double EPS = 1e-8;
const double D_INF = 1e12;
const int I_INF = 1 << 29;
typedef long long LL;

#ifdef __GNUC__
#define mie_bsf(pindex, val) \
    val ? *pindex = __builtin_ctz(val), 1 : 0
#define mie_bsf64(pindex, val) \
    val ? *pindex = __builtin_ctzl(val), 1 : 0

#define mie_bsr(pindex, val) \
        val ? (*pindex = __builtin_clz(val) ^ 0x1f), 1 : 0
#define mie_bsr64(pindex, val) \
        val ? (*pindex = __builtin_clzl(val) ^ 0x3f), 1 : 0

#elif _MSC_VER

#include<intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt64

#define mie_bsf(pindex, val) _BitScanForward( \
    reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsf64(pindex, val) _BitScanForward64( \
    reinterpret_cast<unsigned long *>(pindex), val)

#define mie_bsr(pindex, val) _BitScanReverse( \
        reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsr64(pindex, val) _BitScanReverse64( \
        reinterpret_cast<unsigned long *>(pindex), val)

#endif

int main(){
    int sum, limit;
    scanf("%d%d", &sum, &limit);
    vector<int> res;
    if (sum <= limit)
    {
        for (int i = 1; i < sum; i <<= 1)
        {
            if ((i & sum) != 0)
            {
                res.push_back(i);
            }
        }
    }
    else
    {
        int s = 0;
        vector<vector<int> > bits(32);
        for (int i = 1; i <= limit; i++)
        {
            int out;
            mie_bsf(&out, i);
            s += out + 1;
            bits[out].push_back(i);
        }
        if (s < sum)
        {
            printf("-1\n");
            return 0;
        }
        while (sum > 0)
        {
            int bit;
            mie_bsr(&bit, sum);
            for (int i = bit; i >= 0; i--)
            {
                if (bits[i].size() > 0)
                {
                    res.push_back(*bits[i].rbegin());
                    bits[i].pop_back();
                    sum -= i + 1;
                    break;
                }
            }
        }
    }
    printf("%d\n", res.size());
    for (int i = 0; i < res.size(); i++)
    {
        printf("%d%c", res[i], i + 1 < res.size() ? ' ' : '\n');
    }
    return 0;
}


#define _USE_MATH_DEFINES

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define SREP(s,i,n) for(int i=s;i<(int)(n);++i)
#define REP(i,a) SREP(0,i,a)
#define ALL(a) (a).begin(),(a).end()

#define CLR(a) memset(a,0,sizeof(a))
#define REMOVE_AT(v,i) v.erase(v.begin()+i)

using namespace std;
const double EPS = 1e-8;
const double D_INF = 1e12;
const int I_INF = 1 << 29;
typedef long long LL;

#ifdef __GNUC__
#define mie_bsf(pindex, val) \
    val ? *pindex = __builtin_ctz(val), 1 : 0
#define mie_bsf64(pindex, val) \
    val ? *pindex = __builtin_ctzl(val), 1 : 0

#define mie_bsr(pindex, val) \
        val ? (*pindex = __builtin_clz(val) ^ 0x1f), 1 : 0
#define mie_bsr64(pindex, val) \
        val ? (*pindex = __builtin_clzl(val) ^ 0x3f), 1 : 0

#elif _MSC_VER

#include<intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt64

#define mie_bsf(pindex, val) _BitScanForward( \
    reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsf64(pindex, val) _BitScanForward64( \
    reinterpret_cast<unsigned long *>(pindex), val)

#define mie_bsr(pindex, val) _BitScanReverse( \
        reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsr64(pindex, val) _BitScanReverse64( \
        reinterpret_cast<unsigned long *>(pindex), val)

#endif

int main(){
    int sum, limit;
    scanf("%d%d", &sum, &limit);
    vector<int> res;
    int s = 0;
    vector<vector<int> > bits(32);
    for (int i = 1; i <= limit; i++)
    {
        int out;
        mie_bsf(&out, i);
        s += (1 << out);
        bits[out].push_back(i);
    }
    if (s < sum)
    {
        printf("-1\n");
        return 0;
    }
    while (sum > 0)
    {
        int bit;
        mie_bsr(&bit, sum);
        for (int i = bit; i >= 0; i--)
        {
            if (bits[i].size() > 0)
            {
                res.push_back(*bits[i].rbegin());
                bits[i].pop_back();
                sum -= (1 << i);
                break;
            }
        }
    }
    printf("%d\n", res.size());
    for (int i = 0; i < res.size(); i++)
    {
        printf("%d%c", res[i], i + 1 < res.size() ? ' ' : '\n');
    }
    return 0;
}


#define _USE_MATH_DEFINES

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define SREP(s,i,n) for(int i=s;i<(int)(n);++i)
#define REP(i,a) SREP(0,i,a)
#define ALL(a) (a).begin(),(a).end()

#define CLR(a) memset(a,0,sizeof(a))
#define REMOVE_AT(v,i) v.erase(v.begin()+i)

using namespace std;
const double EPS = 1e-8;
const double D_INF = 1e12;
const int I_INF = 1 << 29;
typedef long long LL;

#ifdef __GNUC__
#define mie_bsf(pindex, val) \
    val ? *pindex = __builtin_ctz(val), 1 : 0
#define mie_bsf64(pindex, val) \
    val ? *pindex = __builtin_ctzl(val), 1 : 0

#define mie_bsr(pindex, val) \
        val ? (*pindex = __builtin_clz(val) ^ 0x1f), 1 : 0
#define mie_bsr64(pindex, val) \
        val ? (*pindex = __builtin_clzl(val) ^ 0x3f), 1 : 0

#elif _MSC_VER

#include<intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt64

#define mie_bsf(pindex, val) _BitScanForward( \
    reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsf64(pindex, val) _BitScanForward64( \
    reinterpret_cast<unsigned long *>(pindex), val)

#define mie_bsr(pindex, val) _BitScanReverse( \
        reinterpret_cast<unsigned long *>(pindex), val)
#define mie_bsr64(pindex, val) _BitScanReverse64( \
        reinterpret_cast<unsigned long *>(pindex), val)

#endif

int main(){
    int sum, limit;
    scanf("%d%d", &sum, &limit);
    vector<int> res;
    if (sum <= limit)
    {
        for (int i = 1; i <= sum; i <<= 1)
        {
            if ((i & sum) != 0)
            {
                res.push_back(i);
            }
        }
    }
    else
    {
        int s = 0;
        vector<vector<int> > bits(32);
        for (int i = 1; i <= limit; i++)
        {
            int out;
            mie_bsf(&out, i);
            s += out + 1;
            bits[out].push_back(i);
        }
        if (s < sum)
        {
            printf("-1\n");
            return 0;
        }
        while (sum > 0)
        {
            int bit;
            mie_bsr(&bit, sum);
            for (int i = bit; i >= 0; i--)
            {
                if (bits[i].size() > 0)
                {
                    res.push_back(*bits[i].rbegin());
                    bits[i].pop_back();
                    sum -= (1 << i);
                    break;
                }
            }
        }
    }
    printf("%d\n", res.size());
    for (int i = 0; i < res.size(); i++)
    {
        printf("%d%c", res[i], i + 1 < res.size() ? ' ' : '\n');
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>
#include <iostream>

using namespace std;

int masks[31] = {
};

int _getSumVal(int val)
{
	int i;
	if (val == 0)
		return 0;
	for (i = 0; i < 31; i++)
	{
		if (val & masks[i])
			return val & masks[i];
	}
	return 0;
}

void _initMasks()
{
	int i;
	masks[0] = 1;
	for (i = 1; i <= 30; i++)
	{
		masks[i] = (masks[i - 1] << 1);
	}
}

bool _doSum(list<int> &a, int sum)
{
	int i;
	__int64 s, v, k;
	list<int>::const_iterator it;

	s = 0;
	it = a.begin();
	while (it != a.end())
	{
		v = _getSumVal(*it);
		s += v;
		it++;
	}

	v = s - sum;
	if (v < 0)
		return false;

	/*
	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if (v & k)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}
	*/

	it = a.end();
	it--;
	while (it != a.begin())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if ((v - k) >= 0)
		{
			v -= k;
			it = a.erase(it);
			it--;
			continue;
		}
		it--;
	}

	if (v != 0)
	{
		k = _getSumVal(*it);
		if ((v - k) >= 0)
		{
			v -= k;
			it = a.erase(it);
		}
	}

return v == 0;
}

//#define PRINT_CLOCKS
void _solve()
{
	int i, j, n, sum, limit;
	list<int> vals;

	_initMasks();
	scanf("%d %d", &sum, &limit);

	for (i = 0; i < limit; i++)
		vals.push_back(i + 1);

	if (_doSum(vals, sum))
	{
		printf("%d\n", vals.size());
		list<int>::const_iterator it = vals.begin();
		while (it != vals.end())
		{
			printf("%d ", *it);
			it++;
		}
	}
	else
	{
		printf("-1");
	}

#if defined(PRINT_CLOCKS)
	printf("msek = %f\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

int main()
{
	_solve();
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>
#include <iostream>

using namespace std;

int masks[31] = {
};

int _getSumVal(int val)
{
	int i;
	if (val == 0)
		return 0;
	for (i = 0; i < 31; i++)
	{
		if (val & masks[i])
			return val & masks[i];
	}
	return 0;
}

void _initMasks()
{
	int i;
	masks[0] = 1;
	for (i = 1; i <= 30; i++)
	{
		masks[i] = (masks[i - 1] << 1);
	}
}

bool _doSum(list<int> &a, int sum)
{
	int i;
	__int64 s, v, k;
	list<int>::const_iterator it;

	s = 0;
	it = a.begin();
	while (it != a.end())
	{
		v = _getSumVal(*it);
		s += v;
		it++;
	}

	v = s - sum;
	if (v < 0)
		return false;

	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if (v & k)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}

	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if ((v - k) >= 0)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}

	return v == 0;
}

//#define PRINT_CLOCKS
void _solve()
{
	int i, j, n, sum, limit;
	list<int> vals;

	_initMasks();
	scanf("%d %d", &sum, &limit);

	for (i = 0; i < limit; i++)
		vals.push_back(i + 1);

	if (_doSum(vals, sum))
	{
		printf("%d\n", vals.size());
		list<int>::const_iterator it = vals.begin();
		while (it != vals.end())
		{
			printf("%d ", *it);
			it++;
		}
	}
	else
	{
		printf("-1");
	}

#if defined(PRINT_CLOCKS)
	printf("msek = %f\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

int main()
{
	_solve();
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>
#include <iostream>

using namespace std;

int masks[31] = {
};

int _getSumVal(int val)
{
	int i;
	if (val == 0)
		return 0;
	for (i = 0; i < 31; i++)
	{
		if (val & masks[i])
			return val & masks[i];
	}
	return 0;
}

void _initMasks()
{
	int i;
	masks[0] = 1;
	for (i = 1; i <= 30; i++)
	{
		masks[i] = (masks[i - 1] << 1);
	}
}

bool _doSum(list<int> &a, int sum)
{
	int i;
	__int64 s, v, k;
	list<int>::const_iterator it;

	s = 0;
	it = a.begin();
	while (it != a.end())
	{
		v = _getSumVal(*it);
		s += v;
		it++;
	}

	v = s - sum;
	if (v < 0)
		return false;

	/*
	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if (v & k)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}
	*/

	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if ((v - k) >= 0)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}

return v == 0;
}

//#define PRINT_CLOCKS
void _solve()
{
	int i, j, n, sum, limit;
	list<int> vals;

	_initMasks();
	scanf("%d %d", &sum, &limit);

	for (i = 0; i < limit; i++)
		vals.push_back(i + 1);

	if (_doSum(vals, sum))
	{
		printf("%d\n", vals.size());
		list<int>::const_iterator it = vals.begin();
		while (it != vals.end())
		{
			printf("%d ", *it);
			it++;
		}
	}
	else
	{
		printf("-1");
	}

#if defined(PRINT_CLOCKS)
	printf("msek = %f\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

int main()
{
	_solve();
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>
#include <iostream>

using namespace std;

int masks[31] = {
};

int _getSumVal(int val)
{
	int i;
	if (val == 0)
		return 0;
	for (i = 0; i < 31; i++)
	{
		if (val & masks[i])
			return val & masks[i];
	}
	return 0;
}

void _initMasks()
{
	int i;
	masks[0] = 1;
	for (i = 1; i <= 30; i++)
	{
		masks[i] = (masks[i - 1] << 1);
	}
}

bool _doSum(list<int> &a, int sum)
{
	int i;
	__int64 s, v, k;
	list<int>::const_iterator it;

	s = 0;
	it = a.begin();
	while (it != a.end())
	{
		v = _getSumVal(*it);
		s += v;
		it++;
	}

	v = s - sum;
	if (v < 0)
		return false;

	it = a.begin();
	while (it != a.end())
	{
		if (v == 0)
			break;
		k = _getSumVal(*it);
		if (v & k)
		{
			v -= k;
			it = a.erase(it);
			continue;
		}
		it++;
	}

	return v == 0;
}

//#define PRINT_CLOCKS
void _solve()
{
	int i, j, n, sum, limit;
	list<int> vals;

	_initMasks();
	scanf("%d %d", &sum, &limit);

	for (i = 0; i < limit; i++)
		vals.push_back(i + 1);

	if (_doSum(vals, sum))
	{
		printf("%d\n", vals.size());
		list<int>::const_iterator it = vals.begin();
		while (it != vals.end())
		{
			printf("%d ", *it);
			it++;
		}
	}
	else
	{
		printf("-1");
	}

#if defined(PRINT_CLOCKS)
	printf("msek = %f\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

int main()
{
	_solve();
	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <functional>

using namespace std;

vector<int> used;
vector<long long> nums;

long long l;

bool IsPowerOfTwo(long long x)
{
	return (x != 0) && ((x & (x - 1)) == 0);
}

void find(long long n, vector<int>& out) {
	if (n == -1) {
		cout << -1 << endl;
		exit(0);
	}

	long long res = nums[n];

	if (res <= l) {
		used[res] = true;
		out.push_back(res);
		long long tmp = nums[n] >> n;
		if (IsPowerOfTwo(tmp + 1)) {
			nums[n] = (tmp + 2) << n;
		}
		else {
			nums[n] = (tmp + 1) << n;
		}

		return;
	}

	find(n - 1, out);
	find(n - 1, out);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int s;
	cin >> s >> l;

	used.resize(l + 1);

	vector<int> bin;

	while (s) {
		bin.push_back(s % 2);
		s /= 2;
	}

	nums.resize(bin.size() + 1);

	vector<int> ans;

	for (int i = 0; i < bin.size(); i++) {
		nums[i] = 1 << i;
		if (bin[i]) {
			find(i, ans);
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <functional>

using namespace std;

vector<int> used;

int l;

void find(int n, vector<int>& out) {
	if (n == 0) {
		cout << -1 << endl;
		exit(0);
	}

	int res = n;

	while (res <= l && used[res]) {
		res = res * 2 + res;
	}

	if (res <= l) {
		used[res] = true;
		out.push_back(res);
		return;
	}

	find(n / 2, out);
	find(n / 2, out);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int s;
	cin >> s >> l;

	used.resize(l + 1);

	vector<int> bin;

	while (s) {
		bin.push_back(s % 2);
		s /= 2;
	}

	vector<int> ans;

	for (int i = 0; i < bin.size(); i++) {
		if (bin[i]) {
			if ((1 << i) <= l) {
				ans.push_back(1 << i);
				used[ans.back()] = true;
			}
		}
	}

	for (int i = 0; i < bin.size(); i++) {
		if (bin[i]) {
			if ((1 << i) > l) {
				find(1 << i, ans);
			}
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <functional>

using namespace std;

vector<int> used;
vector<int> nums;

int l;

bool IsPowerOfTwo(int x)
{
	return (x != 0) && ((x & (x - 1)) == 0);
}

void find(int n, vector<int>& out) {
	if (n == -1) {
		cout << -1 << endl;
		exit(0);
	}

	int res = nums[n];

	if (res <= l) {
		used[res] = true;
		out.push_back(res);
		int tmp = nums[n] >> n;
		if (IsPowerOfTwo(tmp + 1)) {
			nums[n] = (tmp + 2) << n;
		}
		else {
			nums[n] = (tmp + 1) << n;
		}

		return;
	}

	find(n - 1, out);
	find(n - 1, out);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int s;
	cin >> s >> l;

	used.resize(l + 1);

	vector<int> bin;

	while (s) {
		bin.push_back(s % 2);
		s /= 2;
	}

	nums.resize(bin.size() + 1);

	vector<int> ans;

	for (int i = 0; i < bin.size(); i++) {
		nums[i] = 1 << i;
		if (bin[i]) {
			find(i, ans);
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <functional>

using namespace std;

vector<int> used;
vector<long long> nums;

long long l;

bool IsPowerOfTwo(long long x)
{
	return (x != 0) && ((x & (x - 1)) == 0);
}

void find(long long n, vector<int>& out) {
	if (n == -1) {
		cout << -1 << endl;
		exit(0);
	}

	long long res = nums[n];

	if (res <= l) {
		used[res] = true;
		out.push_back(res);

		long long tmp = nums[n] >> (n + 1);
		nums[n] = ((tmp + 1) << (n + 1)) + (1 << n);

		return;
	}

	find(n - 1, out);
	find(n - 1, out);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int s;
	cin >> s >> l;

	used.resize(l + 1);

	vector<int> bin;

	while (s) {
		bin.push_back(s % 2);
		s /= 2;
	}

	nums.resize(bin.size() + 1);

	vector<int> ans;

	for (int i = 0; i < bin.size(); i++) {
		nums[i] = 1 << i;
		if (bin[i]) {
			find(i, ans);
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main () {
	vector <int> outout;
	int sum, lim, out = 1;

	cin >> sum >> lim;

	while (out * 2 <= lim && out * 2 <= sum) {
		out *= 2;
	}

	while (sum > 0 && out != 0) {
		for (int i = out; i <= lim && sum > 0; i += out) {
			if (sum < out) {
				break;
			}
			if ((i / out) % 2 != 0) {
				sum -= out;
				outout.push_back(i);
			}
		}
		out /= 2;
	}

	if (sum != 0) {
		cout << -1;
		return 0;
	}

	cout << outout.size() << endl;

	for (int i = 0; i < outout.size(); i++) {
		cout << outout[i] << " ";
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main () {
	vector <int> outout;
	int sum, lim, out = 1;

	cin >> sum >> lim;

	while (out * 2 <= lim && out * 2 <= sum) {
		out *= 2;
	}

	while (sum > 0 && out != 1) {
		if (sum >= out) {
			sum -= out;
			outout.push_back(out);
		}
		out /= 2;
	}

	for (int i = 1; i <= lim && sum > 0; i += 2) {
		outout.push_back(i);
		sum--;
	}

	if (sum != 0) {
		cout << -1;
		return 0;
	}

	cout << outout.size() << endl;

	for (int i = 0; i < outout.size(); i++) {
		cout << outout[i] << " ";
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main ()
{
	int s,limit;
	cin>>s>>limit;
	vector < pair<int,int> > ans;
	//cout<<s1<<endl;
	int ans1 = 0;
	for (int i = limit;i>=1;i--)
	{
		char buff[50];
		string s1 = _itoa(i,buff,2);
		int j;
		for (j = s1.length() - 1;j>=0;j--) if (s1[j]=='1') break;
		ans.push_back(make_pair(((int)pow((double)2,(int)s1.length() - 1 - j)),i));
	}
	sort(ans.begin(),ans.end());
	vector <int> ans2;
	for (int i = ans.size() - 1;i>=0;i--)
	{
		if (ans1  + ans[i].first <= s) {ans1 = ans[i].first + ans1;ans2.push_back(ans[i].second);}
		if (ans1==s) break;
	}
	if (ans1==s)
	{
		cout<<ans2.size()<<endl;
		for (int i = 0;i<ans2.size();i++) cout<<ans2[i]<<" ";
	}
	else cout<<-1;
	//system("pause");
	return 0;
}


S, L = map(int, input().split())

d, r = {}, {}
k = 0
while L > 2**k:
    d[2**k] = (L+2**k)//2**(k+1)
    k += 1

for i in sorted(d.keys())[::-1]:
    while i <= S and d[i]:
        S -= i
        d[i] -= 1
        r[i] = r.get(i, 0) + 1

ans = []
for i in sorted(r.keys())[::-1]:
    for j in range(d[i] + r[i] - 1, d[i]-1, -1):
        ans += [str((2*j + 1)*i)]
print(len(ans))
print(-1 if S else ' '.join(ans))


S, L = map(int, input().split())

d, r = {}, {}
k = 0
while L > 2**k:
    d[2**k] = (L+2**k)//2**(k+1)
    k += 1

for i in sorted(d.keys())[::-1]:
    while i <= S and d[i]:
        S -= i
        d[i] -= 1
        r[i] = r.get(i, 0) + 1

ans = []
for i in sorted(r.keys())[::-1]:
    for j in range(d[i] + r[i] - 1, d[i]-1, -1):
        ans += [str((2*j + 1)*i)]
if S:
    print(-1)
else:
    print(len(ans))
    print(' '.join(ans))


S, L = map(int, input().split())

d, r = {}, {}
k = 0
while L > 2**k:
    d[2**k] = (L+2**k)//2**(k+1)
    k += 1

for i in sorted(d.keys())[::-1]:
    while i <= S and d[i]:
        S -= i
        d[i] -= 1
        r[i] = r.get(i, 0) + 1

ans = []
for i in sorted(r.keys())[::-1]:
    for j in range(d[i] + r[i] - 1, d[i]-1, -1):
        ans += [str((2*j + 1)*i)]
print(-1 if S else ' '.join(ans))


S, L = map(int, input().split())

d, r = {}, {}
k = 0
while L > 2**k:
    d[2**k] = (L+2**k)//2**(k+1)
    k += 1

for i in sorted(d.keys())[::-1]:
    while i <= S and d[i]:
        S -= i
        d[i] -= 1
        r[i] = r.get(i, 0) + 1

ans = ''
for i in r:
    for j in range(r[i]):
        ans += str((2*j + 1)*i) + ' '
print(ans if ans else -1)


S, L = map(int, input().split())

d, r = {}, {}
k = 0
while L >= 2**k:
    d[2**k] = (L+2**k)//2**(k+1)
    k += 1

for i in sorted(d.keys())[::-1]:
    while i <= S and d[i]:
        S -= i
        d[i] -= 1
        r[i] = r.get(i, 0) + 1

ans = []
for i in sorted(r.keys())[::-1]:
    for j in range(d[i] + r[i] - 1, d[i]-1, -1):
        ans += [str((2*j + 1)*i)]
if S:
    print(-1)
else:
    print(len(ans))
    print(' '.join(ans))


s,l=map(int,input().split())
lowbit=[0]
idx=[0]
for i in range(1,l+1):
    x=bin(i)
    x=x[::-1]
    lowbit.append(2**x.index("1"))
    idx.append(i)
idx.sort(key=lambda i:lowbit[i],reverse=True)
p=0
ans=[]
while(s and p<l):
    if lowbit[idx[p]]<=s:
        s-=lowbit[idx[p]]
        ans.append(idx[p])
    p+=1
if s:
    print(-1)
else:
    print(len(ans))
    print(*ans)


s, l = map(int, input().spilt())
t = []
for i in range(l, 0, -1):
    k = i & (i ^ (i - 1))
    if s >= k:
        t.append(str(i))
        s -= k
print(-1 if s else str(len(t)) + '\n' + ' '.join(t))


s, l = map(int, input().split())
t = []
for i in range(l, 0, -1):
    k = i & (i ^ (i - 1))
    if s >= k:
        t.append(str(i))
        s -= k
print(-1 if s else str(len(t)) + '\n' + ' '.join(t))


sum,limit = map(int,input().split())

def lowbit(k):
    count = 0
    for i in k[::-1]:
        if i == '1':
            return 2**count

        else:
            count+=1

actual = 0
max = 0
for i in range(1,limit+1):
    c = bin(i)[2:]

    if lowbit(c)>max:
         max = lowbit(c)
    actual+=lowbit(c)

if sum<=actual:
 ans = []
 count = 0
 for i in range(limit,0,-1):

      count+=lowbit(bin(i)[2:])
      # print(count)
      ans.append(i)
      if count > sum:

         count-=lowbit(bin(i)[2:])
         # print(count)
         ans.pop(-1)

 # print(count)
 print(len(ans))
 print(*ans)

else:
    print(-1)


sum,limit = map(int,input().split())

def lowbit(k):
    count = 0
    for i in k[::-1]:
        if i == '1':
            return 2**count

        else:
            count+=1

actual = 0
max = 0
for i in range(1,limit+1):
    c = bin(i)[2:]

    if lowbit(c)>max:
         max = lowbit(c)
    actual+=lowbit(c)

if sum<=actual:
 ans = []
 count = 0
 for i in range(max,2,-2):

      count+=lowbit(bin(i)[2:])
      # print(count)
      ans.append(i)
      if count > sum:

         count-=lowbit(bin(i)[2:])
         # print(count)
         ans.pop(-1)
         break

 for i in range(1,limit+1,2):

    if count == sum:
        break
    else:

        count+=lowbit(bin(i)[2:])
        ans.append(i)
 # print(count,actual,max)
 print(len(ans))
 print(*ans)

else:
    print(-1)


sum,limit = map(int,input().split())

def lowbit(k):
    count = 0
    for i in k[::-1]:
        if i == '1':
            return 2**count

        else:
            count+=1

actual = 0
for i in range(1,limit+1):
    c = bin(i)[2:]

    actual+=lowbit(c)
# print(actual)
if sum<=actual:
 ans = []
 count = 0
 for i in range(2,limit+1,2):

      count+=lowbit(bin(i)[2:])
      # print(count)
      ans.append(i)
      if count > sum:

         count-=lowbit(bin(i)[2:])
         ans.pop(-1)
         break

 for i in range(1,limit+1,2):

    if count == sum:
        break
    else:

        count+=lowbit(bin(i)[2:])
        ans.append(i)

 print(len(ans))
 print(*ans)

else:
    print(-1)


sum,limit = map(int,input().split())

def lowbit(k):
    count = 0
    for i in k[::-1]:
        if i == '1':
            return 2**count

        else:
            count+=1

actual = 0
max = 0
for i in range(1,limit+1):
    c = bin(i)[2:]

    if lowbit(c)>max:
         max = lowbit(c)
    actual+=lowbit(c)

if sum<=actual:
 ans = []
 count = 0
 for i in range(max,1,-2):

      count+=lowbit(bin(i)[2:])
      # print(count)
      ans.append(i)
      if count > sum:

         count-=lowbit(bin(i)[2:])
         # print(count)
         ans.pop(-1)
         break

 for i in range(1,limit+1,2):

    if count == sum:
        break
    else:

        count+=lowbit(bin(i)[2:])
        ans.append(i)
 # print(count,actual,max)
 print(len(ans))
 print(*ans)

else:
    print(-1)


sum,limit = map(int,input().split())

def lowbit(k):
    count = 0
    for i in k[::-1]:
        if i == '1':
            return 2**count

        else:
            count+=1

actual = 0
max = 0
for i in range(1,limit+1):
    c = bin(i)[2:]

    if lowbit(c)>max:
         max = lowbit(c)
    actual+=lowbit(c)

if sum<=actual:
 ans = []
 count = 0
 for i in range(limit+1,0,-1):

      count+=lowbit(bin(i)[2:])
      # print(count)
      ans.append(i)
      if count > sum:

         count-=lowbit(bin(i)[2:])
         # print(count)
         ans.pop(-1)

 # print(count)
 print(len(ans))
 print(*ans)

else:
    print(-1)


sum, lim = map(int, input().split())
arr = []

now = 0
for i in range(lim, -1, -1):
    if now + (i & (-i)) <= sum:
        now += i & (-i)
        arr.append(i)

if now != sum:
    print(-1)
else:
    print(len(arr) - 1)
    for i in range(0, len(arr) - 1):
        print(arr[i])


class Pair(object):
    def __init__(self, f, s):
        self.f = f
        self.s = s
    def __lt__(a,b):
        return a.f < b.f
    def __gt__(a,b):
        return a.f > b.f

sum, lim = map(int, input().split())
arr = []
used = []
for i in range(1, lim + 1):
    arr.append(Pair(i & (-i), i))

arr.sort()

for i in range(lim-1,-1,-1):
    if sum >= arr[i].f:
        sum -= arr[i].f
        used.append(i)
    if sum == 0:
        break

if sum < 0:
    print("-1")
else:
    print(str(len(used))+" "+str(arr[used[0]].s))
    for i in range(1, len(used)):
        print(str(arr[used[i]].s))


s, l = map(int, input().split())
t = []
for i in range(l, 0, -1):
    k = i & (-i)
    if s >= k:
        t.append(str(i))
        s -= k
print(-1 if s else str(len(t)) + '\n' + ' '.join(t))


s,l=map(int,input().split())
r=[]
while (l>0 and s>0):
    if s-(l&l)>=0:
        s-=(l&-l)
        r.append(l)
    l-=1
if s!=0:
    print(-1)
else:
    print(len(r))
    print(*r)


s, limit = [int(c) for c in input().split()]

def lowbit(a):
    res = 1
    while a % 2 == 0:
        res += 1
        a = a // 2

    return res

a = [0] * 20
examples = [[] for _ in range(20)]

for i in range(1, limit+1):
    a[lowbit(i)] += 1
    examples[lowbit(i)].append(i)

length = -1
res = []
c = 1
#
# print(a)
# print(examples)

while s != 0:
    if s <= a[1]:
        res = res + examples[1][:s]
        length += s
        s = 0
    else:
        # print("{0:b}".format(s))
        max_pow = len("{0:b}".format(s))
        while max_pow != 1 and a[max_pow] == 0:
            max_pow -= 1

        if max_pow == 1:
            length = -2
            s = 0
        else:
            # print(s, 2**(max_pow-1))
            s = s - 2**(max_pow-1)
            length +=1
            ex = examples[max_pow].pop()
            a[max_pow] -= 1
            res.append(ex)

print(length + 1)

if length > 0:
    print(' '.join(map(str,res)))


s, limit = [int(c) for c in input().split()]

def lowbit(a):
    res = 1
    while a % 2 == 0:
        res += 1
        a = a // 2

    return res

a = [0] * 20
examples = [[] for _ in range(20)]

for i in range(1, limit+1):
    a[lowbit(i)] += 1
    examples[lowbit(i)].append(i)

length = -1
res = []
c = 1
#
# print(a)
# print(examples)

while s != 0:
    if s <= a[1]:
        res = res + examples[1][:s]
        length += s
        s = 0
    else:
        # print("{0:b}".format(s))
        max_pow = len("{0:b}".format(s))
        while max_pow != 1 and a[max_pow] == 0:
            max_pow -= 1

        if max_pow == 1:
            length = -2
            s = 0
        else:
            # print(s, 2**(max_pow-1))
            s = s - 2**(max_pow-1)
            length +=1
            ex = examples[max_pow].pop()
            a[max_pow] -= 1
            res.append(ex)

print(length + 1)

if length >= 0:
    print(' '.join(map(str,res)))


s, limit = [int(c) for c in input().split()]

def lowbit(a):
    res = 1
    while a % 2 == 0:
        res += 1
        a = a // 2

    return res

a = [0] * 20
examples = [[] for _ in range(20)]

for i in range(1, limit+1):
    a[lowbit(i)] += 1
    examples[lowbit(i)].append(i)

length = -1
res = []
c = 1

# print(a)
# print(examples)

while s != 0:
    if s <= a[1]:
        res = res + examples[1][:s]
        length += s
        s = 0
    else:
        max_pow = len("{0:b}".format(s))
        while max_pow != 1 and a[max_pow] == 0:
            max_pow -= 1

        if max_pow == 1:
            length = -2
            s = 0
        else:
            s = s - 2**(max_pow-1)
            length +=1
            ex = examples[max_pow].pop()
            a[max_pow] -= a[max_pow]
            res.append(ex)

print(length + 1)

if length != -1:
    print(' '.join(map(str,res)))


def f(n):
    m=n
    c=0
    while m%2==0:
        m=m//2
        c=c+1
    if m*(2**c)==n:
        return c
    else:
        return 0

s,l=list(map(int,input().split()))
a=[]
if s%2==1:
    a.append(s)
    s=s-1
e=[]
k=0
while not f(s) and s>0:
    s=s-2
    k=k+1
c=f(s)
e.append(2**c)
x=1
while k>0:
    if k%2==1:
        e.append(2**x)
        k=k//2
        x=x+1
    else:
        k=k//2
        x=x+1
e.sort()
for i in range(len(e)):
    if i==0:
        a.append(e[i])
        c=0
    else:
        if e[i]==e[i-1]:
            c=c+1
            a.append(e[i-1]+e[i-1]*2*c)
        else:
            a.append(e[i])
            c=0
if len(a)>l:
    print(-1)
else:
    print(len(a))
    for i in range(len(a)-1):
        print(a[i],end=' ')
    print(a[-1])


def f(n):
    m=n
    c=0
    while m%2==0:
        m=m//2
        c=c+1
    if m*(2**c)==n:
        return c
    else:
        return 0

s,l=list(map(int,input().split()))
a=[]
if s%2==1:
    a.append(s)
    s=s-1
e=[]
k=0
while not f(s) and s>0:
    s=s-2
    k=k+1
c=f(s)
e.append(2**c)
x=1
while k>0:
    if k%2==1:
        e.append(2**x)
        k=k//2
        x=x+1
    else:
        k=k//2
        x=x+1
e.sort()
for i in range(len(e)):
    if i==0:
        a.append(e[i])
        c=0
    else:
        if e[i]==e[i-1]:
            c=c+1
            a.append(e[i-1]+e[i-1]*2*c)
        else:
            a.append(e[i])
            c=0
if len(a)>l:
    print(-1)
else:
    print(len(a))
    for i in range(len(a)):
        print(a[i],end=' ')


s, l = map(int, input().split())

b = list([int(x) for x in bin(min(s,l))[2:]])

i = 0
ans = []
while s > 0 and i < len(b):
    k = len(b) - i - 1
    a = 2**(len(b) -1 - k)
    n = 2**k
    while s >= 2**k  and a > 0:
        s -= 2**k
        a -= 1
        ans.append(str(n))
        n += 2**(k+1)
    i += 1

if s != 0:
    print(-1)
else:
    print(len(ans))
    print(' '.join(ans))


s, l = map(int, input().split())

b = list([int(x) for x in bin(min(s,l))[2:]])

i = 0
ans = []
while s > 0 and i < len(b):
    k = len(b) - i - 1
    a = 2**(len(b) -1 - k)
    n = 2**k
    while n <= l and s >= 2**k  and a > 0:
        s -= 2**k
        a -= 1
        ans.append(str(n))
        n += 2**(k+1)
    i += 1

if s != 0:
    print(-1)
else:
    print(len(ans))
    print(' '.join(ans))


s, l = map(int, input().split())

b = list([int(x) for x in bin(min(s,l))[2:]])

i = 0
ans = []
while s > 0 and i < len(b):
    k = len(b) - i - 1
    a = 2**(len(b) -1 - k)
    n = 2**k
    while n < l and s >= 2**k  and a > 0:
        s -= 2**k
        a -= 1
        ans.append(str(n))
        n += 2**(k+1)
    i += 1

if s != 0:
    print(-1)
else:
    print(len(ans))
    print(' '.join(ans))


__author__ = 'asmn'

s, l = tuple(map(int, input().split(' ')))
t = 1
while (t << 1) <= s:
    t <<= 1

ans = []
while s > 0 and t > 0:
    n = min((l // t + 1)//2, s // t)
    s -= t * n
    for i in range(n):
        ans.append((i*2+1) * t)
    t >>= 1

if s > 0:
    print(-1)
else:
    print(len(ans))
    print(*tuple(ans))


def main():
    _sum, limit = map(int, input().split())

    cur_sum = 0
    cur_div = limit
    ans = []
    while cur_sum <= _sum and cur_div >= 1:
        bin_div = bin(cur_div)[2:]
        lowest1 = bin_div.rfind('1')
        contr = 2 ** (len(bin_div) - lowest1 - 1)
        assert contr == (cur_div&-cur_div)
        if cur_sum + contr <= _sum:
            cur_sum += contr
            ans.append(cur_div)

        cur_div -= 1

    print(cur_sum)

    if cur_sum == _sum:
        print(len(ans))
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


def main():
    _sum, limit = map(int, input().split())

    ans = []
    for i in range(limit, 0, -1):
        if _sum - (i & -i) >= 0:
            _sum -= (i & -i)
            ans.append(i)

        if _sum <= 0:
            break

    if _sum > 0:
        print(-1)
    else:
        print(len(ans))
        print(*ans)

if __name__ == "__main__":
    main()


def main():
    _sum, limit = map(int, input().split())

    cur_sum = 0
    cur_div = limit
    ans = []
    while cur_sum <= _sum and cur_div >= 1:
        bin_div = bin(cur_div)[2:]
        lowest1 = bin_div.rfind('1')
        contr = 2 ** (len(bin_div) - lowest1 - 1)
        assert contr == (cur_div&-cur_div)
        if cur_sum + contr <= _sum:
            cur_sum += contr
            ans.append(cur_div)

        cur_div -= 1

    print(cur_sum)

    if cur_sum == _sum:
        print(len(ans))
        print(*ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


def main():
    _sum, limit = map(int, input().split())

    cur_sum = 0
    cur_div = limit
    ans = []
    while cur_sum <= _sum and cur_div >= 1:
        bin_div = bin(cur_div)[2:]
        lowest1 = bin_div.rfind('1')
        contr = 2 ** (len(bin_div) - lowest1 - 1)
        if cur_sum + contr <= _sum:
            cur_sum += contr
            ans.append(cur_div)

        cur_div -= 1

    if cur_sum == _sum:
        print(len(ans))
        print(*ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


def main():
    _sum, limit = map(int, input().split())

    cur_sum = 0
    cur_div = limit
    ans = set()
    while cur_sum < _sum and cur_div >= 1:
        bin_div = bin(cur_div)[2:]
        lowest1 = bin_div.rfind('1')
        if lowest1 != -1:
            cur_sum += 2 ** int(len(bin_div) - lowest1 - 1)
            ans.add(cur_div)

        cur_div -= 1

    if cur_sum == _sum:
        print(len(ans))
        print(*ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


def main():
    _sum, limit = map(int, input().split())

    cur_sum = 0
    cur_div = limit
    ans = []
    while cur_sum <= _sum and cur_div >= 1:
        bin_div = bin(cur_div)[2:]
        lowest1 = bin_div.rfind('1')
        contr = 2 ** (len(bin_div) - lowest1 - 1)
        assert contr == (cur_div&-cur_div)
        if cur_sum + contr <= _sum:
            cur_sum += contr
            ans.append(cur_div)

        cur_div -= 1

    if cur_sum == _sum:
        print(len(ans))
        print(*ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


while True:
	try:
		def solution(s, l ):
			ans = list()
			i = l
			idn=  t = 1
			while i >= 1:
				tr = i & t
				if tr > 0 and t <= s:
					s -= t
					ans.append(i)
					t,  i= 1, i-1

				elif tr > 0 and t > s:
					i -= 1
					t = 1
				else:
					t *= 2
				if s == 0:
					break
			if s==0:
				print(len(ans))
				print(*ans)
			else:print(-1)

		def read():
			sum,  limit = map(int, input().split())
			solution(sum, limit)

		if __name__ == "__main__":
			read()
	except EOFError:
		break


sum, limit = map(int, input().split(' '))

ans = set()

def low_bit(n):
    k = 0
    while not n & (1 << k):
        k += 1
    return 1 << k

for i in reversed(range(1, limit + 1)):
    t = low_bit(i)
    if sum >= t:
        sum -= t
        ans.add(i)

if sum == 0:
    print(len(ans))
    print(' '.join([str(x) for x in ans]))
else:
    print(-1)


sum, limit = map(int, input().split(' '))

ans = set()

def low_bit(n):
    k = 0
    while not n & (1 << k):
        k += 1
    return 1 << k

for i in reversed(range(1, limit + 1)):
    t = low_bit(i)
    if sum >= t:
        sum -= t
        ans.add(i)

print(sum)

if sum == 0:
    print(len(ans))
    print(' '.join([str(x) for x in ans]))
else:
    print(-1)


sum, limit = map(int, input().split(' '))

ans = set()

def low_bit(n):
    k = 0
    while not n & (1 << k):
        k += 1
    return 1 << k

for i in range(1, limit + 1):
    t = low_bit(i)
    if sum >= t:
        sum -= t
        ans.add(i)

if sum == 0:
    print(len(ans))
    print(' '.join([str(x) for x in ans]))
else:
    print(-1)


def lowval(i):
    global low
    return(low[i])

# Main:
s, lim = list(map(int, input().split()))
low = [0]
result = []

# Create the list of lowbits
m, pm = 1, 1
while len(low) - 1 < lim:
    pm = len(low) - 1
    low += low[1:len(low) - 1] + [m]
    m *= 2
else:
    if len(low) - 1 == lim:
        pm = len(low) - 1

d = list(range(lim + 1))

x  = sorted(d, key=lowval)
x2 = list(map(lowval, x))

for i in range(lim, 0, -1):
    if x2[i] <= s:
        result.append(x[i])
        s -= x2[i]
    if s == 0:
        break

if s != 0:
    print(-1)
else:
    print(len(result))
    for i in result:
        print(i, end=' ')
    print()


target, limit = map(int, input().split())

def lowbit(x):
    return x & (x ^ (x - 1))

ans = []
for i in range(limit, 0, -1):
    x = lowbit(i)
    if x <= target:
        ans.append(i)
        target -= x

if target:
    print(-1)
else:
    print(len(ans))
    print(" ".join(map(str, ans)))


import logging
import copy
import sys
import math

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

# def solve(firstLine):

def solve(total, limit):
    last_bit = 0
    bits = []
    while limit > 0:
        bit = limit & 0x1
        last_bit += 1
        limit >>= 1
        n = limit if bit == 0 else limit + 1
        bits.append(n)

    bits[-1] = 1

    bit_list = []
    for i in range(len(bits) - 1, -1, -1):
        base = int(math.pow(2, i))
        n = bits[i]

        used = 0

        while total > 0 and total >= base and used < n:
            total -= base
            used += 1
        bit_list.append(used)

    bit_list.reverse()

    result = []
    #log(bits, bit_list)
    for i, n in enumerate(bit_list):
        base = int(math.pow(2, i))
        for j in range(0,n):
            mask = j << (i + 1)
            #log(base, j, i, mask, base | mask)
            result.append(base | mask)

    if total > 0:
        print(-1)
        return
    print(len(result))
    print( " ".join(list(map(lambda x: str(x), result))))

def main():
    firstLine = input().split()
    solve(int(firstLine[0]), int(firstLine[1]))

def log(*message):
    logging.debug(message)

if __name__ == "__main__":
    main()


import logging
import copy
import sys
import math

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

# def solve(firstLine):

def solve(total, limit):
    last_bit = 0
    bits = []
    while limit > 0:
        bit = limit & 0x1
        last_bit += 1
        limit >>= 1
        n = limit if bit == 0 else limit + 1
        bits.append(n)

    bits[-1] = 1

    bit_list = []
    for i in range(len(bits) - 1, -1, -1):
        base = int(math.pow(2, i))
        n = bits[i]

        used = 0

        while total > 0 and total >= base and used < n:
            total -= base
            used += 1
        bit_list.append(used)

    bit_list.reverse()

    result = []
    #log(bits, bit_list)
    for i, n in enumerate(bit_list):
        base = int(math.pow(2, i))
        for j in range(0,n):
            mask = j << (i + 1)
            #log(base, j, i, mask, base | mask)
            result.append(base | mask)

    if total > 0:
        print(-1)
        return

    print( " ".join(list(map(lambda x: str(x), result))))

def main():
    firstLine = input().split()
    solve(int(firstLine[0]), int(firstLine[1]))

def log(*message):
    logging.debug(message)

if __name__ == "__main__":
    main()


s,l=map(int,input().split())

lis =[list() for _ in range(100001)]

for i in range(1,l+1):
    lis[i & (~ (i-1))].append(i)

num=int(pow(2,s.bit_length()-1))

invalid=1
ans=list()
while num:
    if num & s:
        temp=num
        length=1
        while temp:
            while len(lis[temp]):
                if length==0:
                    break
                ans.append(lis[temp].pop())
                length-=1
            length=length<<1
            temp>>=1
        if length:
            invalid=0
    num>>=1

if invalid:
    print(len(ans))
    for var in ans:
        print(var,end=" ")
else:
    print(-1)


# cook your dish here
from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
#(a/b)%m =((a%m)*pow(b,m-2)%m)%m

def lowbit(x):
    return x & (-x)

s,l=I()
a=[]
for i in range(l,0,-1):
    x=lowbit(i)
    if x<=s:
        s-=x
        a.append(i)
    if s==0:
        break
if s!=0:
    print(-1)
    exit()
print(len(a))
print(*a)


def check(num):
    x=str(bin(num))
    j=-1
    for i in range(len(x)-1,-1,-1):
        j+=1
        if(x[i]=='1'):
            break
    return j
s,limit=[int(x) for x in input().split()]
res=[]
for i in range(1,limit+1):
    x=check(i)
    res.append([2**x,i])
res.sort(key=lambda x:x[0])
#print(res)
ans=[]
for i in range(len(res)-1,-1,-1):
    if(s>=res[i][0]):
        s-=res[i][0]
        ans.append(res[i][1])
    if(s==0):
        break
if(s!=0):
    print(-1)
else:
    print(len(ans))
    print(*ans,sep=" ")


def check(num):
    x=str(bin(num))
    j=-1
    for i in range(len(x)-1,-1,-1):
        j+=1
        if(x[i]=='1'):
            break
    return j
s,limit=[int(x) for x in input().split()]
res=[]
for i in range(1,limit+1):
    x=check(i)
    res.append([2**x,i])
res.sort(key=lambda x:x[0])
#print(res)
ans=[]
for i in range(len(res)-1,-1,-1):
    if(s>=res[i][0]):
        s-=res[i][0]
        ans.append(res[i][1])
    if(s==0):
        break
if(s!=0):
    print(-1)
else:
    print(len(ans))


s,limit=map(int,input().split())

Cnt=[[]]
for i in range(10**5):
    Cnt.append([])
Ind=[0]*(10**5+1)

m=0
for i in range(1,limit+1):
    pos=0
    x=i
    while(x%2==0):
        x//=2
        pos+=1
    Cnt[2**pos].append(i)
    m=max(m,2**pos)

L=[]
while(s>0):
    e=s
    for j in range(min(m,s),-1,-1):
        if(Ind[j]<len(Cnt[j])):

            L.append(Cnt[j][Ind[j]])
            Ind[j]+=1
            s-=j
            break
    if(s==e):
        print(-1)
        break
if(s==0):
    print(len(L))
    for item in L:
        print(item,end=" ")


s,limit=map(int,input().split())

Cnt=[[]]
for i in range(10**5):
    Cnt.append([])
Ind=[0]*(10**5+1)

m=0
for i in range(1,limit+1):
    pos=0
    x=i
    while(x%2==0):
        x//=2
        pos+=1
    Cnt[2**pos].append(i)
    m=max(m,2**pos)

L=[]
while(s>0):
    e=s
    for j in range(min(m,s),-1,-1):
        if(Ind[j]<len(Cnt[j])):
            L.append(Cnt[j][Ind[j]])
            Ind[j]+=1
            s-=j
            m=min(m,j)
            break
    if(s==e):
        print(-1)
        break
if(s==0):
    print(len(L))
    for item in L:
        print(item,end=" ")


"""
Codeforces Round 250 Div 2 Problem B

Author  : chaotic_iak
Language: Python 3.3.4
"""

class IOHandlerObject(object):
    def getInput(self, mode=2):
        # 0: String
        # 1: List of strings
        # 2: List of integers
        inputs = input().strip()
        if mode == 0:
            return inputs
        if mode == 1:
            return inputs.split()
        if mode == 2:
            return [int(x) for x in inputs.split()]

    def writeOutput(self, s="\n"):
        if isinstance(s, list): s = " ".join(s)
        print(s)

IOHandler = IOHandlerObject()
g = IOHandler.getInput
w = IOHandler.writeOutput

############################## SOLUTION ##############################
s,l = g()

res = []
i = 16
while i+1:
    c = 1
    while True:
        if 2**i * c > l: break
        if 2**i > s: break
        res.append(2**i * c)
        c += 2
        s -= 2**i
    i -= 1
if s:
    print(-1)
else:
    print(len(res))
    print(" ".join(str(x) for x in res))


x, y = map(int, input().split())
a = []
for i in range(y, 0, -1):
    s = i & (i ^ (i - 1))
    if(x >= s):
        x -= s
        a.append(i);
if(x > 0):
    print(-1)
else:
    print(str(len(a)))
    print(*a)


#! /usr/bin/env python

table = [0] * 17

def maxsum(x):
    b = bin(x)[2:]
    ans = 0
    for i, v in enumerate(reversed(b)):
        if v == '1':
            table[i] += 1
            for n in range(i):
                table[n] += 2 ** (i - n - 1)
    for i, v in enumerate(table):
        ans += 2 ** i * v
    return ans

def lowbit(x):
    b = bin(x)[2:]
    for i, v in enumerate(reversed(b)):
        if v == '1':
            return 2 ** i

s, l = [int(x) for x in input().split()]

candi = []
mm = maxsum(l)
# print(table)
if s > mm:
    print('-1')
else:
    flag = True
    while s:
        for i in reversed(range(len(table))):
            if table[i] > 0 and 2 ** i <= s:
                s -= 2 ** i
                table[i] -= 1
                candi.append(table[i] * 2 ** (i+1) + 2 ** i)
                break
        else:
            flag = False
            break
    if flag:
        for x in candi:
            print(x, end=' ')
        print()
    else:
        print('-1')


#! /usr/bin/env python

table = [0] * 17

def maxsum(x):
    b = bin(x)[2:]
    ans = 0
    for i, v in enumerate(reversed(b)):
        if v == '1':
            table[i] += 1
            for n in range(i):
                table[n] += 2 ** (i - n - 1)
    for i, v in enumerate(table):
        ans += 2 ** i * v
    return ans

def lowbit(x):
    b = bin(x)[2:]
    for i, v in enumerate(reversed(b)):
        if v == '1':
            return 2 ** i

s, l = [int(x) for x in input().split()]

candi = []
mm = maxsum(l)
# print(table)
if s > mm:
    print('-1')
else:
    flag = True
    while s:
        for i in reversed(range(len(table))):
            if table[i] > 0 and 2 ** i <= s:
                s -= 2 ** i
                table[i] -= 1
                candi.append(table[i] * 2 ** (i+1) + 2 ** i)
                break
        else:
            flag = False
            break
    if flag:
        for x in candi:
            print(x, end=' ')
            print()
    else:
        print('-1')


#! /usr/bin/env python

table = [0] * 17

def maxsum(x):
    b = bin(x)[2:]
    ans = 0
    for i, v in enumerate(reversed(b)):
        if v == '1':
            table[i] += 1
            for n in range(i):
                table[n] += 2 ** (i - n - 1)
    for i, v in enumerate(table):
        ans += 2 ** i * v
    return ans

def lowbit(x):
    b = bin(x)[2:]
    for i, v in enumerate(reversed(b)):
        if v == '1':
            return 2 ** i

s, l = [int(x) for x in input().split()]

candi = []
mm = maxsum(l)
# print(table)
# print(mm)
if s > mm:
    print('-1')
else:
    flag = True
    while s:
        for i in reversed(range(len(table))):
            if table[i] > 0 and 2 ** i <= s:
                s -= 2 ** i
                table[i] -= 1
                candi.append(table[i] * 2 ** (i+1) + 2 ** i)
                break
        else:
            flag = False
            break
    if flag:
        print(len(candi))
        for x in candi:
            print(x, end=' ')
        print()
    else:
        print('-1')


"""http://codeforces.com/problemset/problem/437/B"""

def solve(s, limit):
    t, bit_length = limit, 0
    res = []
    while t > 0:
        bit_length += 1
        t = t >> 1
    for i in range(bit_length - 1, 0, -1):
        t = 2 ** i
        if s < t:
            break
        s -= t
        res.append(t)
    if limit % 2 == 0:
        bit_length -= 1
    if bit_length < s:
        return None
    for i in range(bit_length):
        res.append(2 ** i | 1)
        s -= 1
        if s == 0:
            break
    return res

if __name__ == '__main__':
    res = solve(*list(map(int, input().split())))
    if res is None:
        print(-1)
    else:
        print(len(res))
        print(' '.join(str(x) for x in res))


"""http://codeforces.com/problemset/problem/437/B"""
from math import log2

def solve(s, limit):
    res = []
    bit_length = int(log2(limit))
    # iterate through 2^x with x from 0, 1...bit_length-1
    for i in range(bit_length, -1, -1):
        low_bit = 2 ** i
        for j in range(1, limit + 1, 2):  # odd number: 1, 3, 5
            t = low_bit * j
            if low_bit > s or t > limit:
                break
            s -= low_bit
            res.append(t)
    return res if s == 0 else None

if __name__ == '__main__':
    res = solve(*list(map(int, input().split())))
    if res is None:
        print(-1)
    else:
        print(len(res))
        print(' '.join(str(x) for x in res))


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=300050,maxk=5050;
int n,K,a[maxn];
long long ans;
long long f1[maxn],f2[maxk*maxk];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
#endif
	int i,j;
	scanf("%d%d",&n,&K);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	memset(f1,0x3f,sizeof(f1));
	memset(f2,0x3f,sizeof(f2));
	if(K*2<=n)
	{
		f1[0]=0;
		f1[n/K]=a[n/K]-a[1];
		for(i=n/K+1;i<=n;i++)
		{
			f1[i]=f1[i-n/K]+a[i]-a[i-n/K+1];
			if(n%K)
				f1[i]=min(f1[i],f1[i-n/K-1]+a[i]-a[i-n/K]);
		}
		ans=f1[n];
	}
	else
	{
		f2[0]=f2[1]=0;
		for(i=2;i<=n;i++)
		{
			int t=i/2*(i/2+1)+(i&1)*(i/2+1);
			for(j=i;j>=0;j-=2)
			{
				if(j)
					f2[t+j/2]=f2[t+j/2-i/2-1];
				if(j<i)
					f2[t+j/2]=min(f2[t+j/2],f2[t-i+j/2]+a[i]-a[i-1]);
			}
		}
		ans=f2[n/2*(n/2+1)+(n&1)*(n/2+1)+n%K];
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=300050,maxk=5050;
int n,K,a[maxn];
long long ans;
long long f1[maxn],f2[maxk*maxk];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
#endif
	int i,j;
	scanf("%d%d",&n,&K);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	memset(f1,0x3f,sizeof(f1));
	memset(f2,0x3f,sizeof(f2));
	if(K*2<=n)
	{
		f1[0]=0;
		f1[n/K]=a[n/K]-a[1];
		for(i=n/K+1;i<=n;i++)
		{
			f1[i]=f1[i-n/K]+a[i]-a[i-n/K+1];
			if(n%K)
				f1[i]=min(f1[i],f1[i-n/K-1]+a[i]-a[i-n/K]);
		}
		ans=f1[n];
	}
	else
	{
		f2[0]=f2[1]=0;
		for(i=2;i<=n;i++)
		{
			int t=i/2*(i/2+1)+(i&1)*(i/2+1);
			for(j=i;j>=0;j-=2)
			{
				if(j)
					f2[t+j/2]=f2[t+j/2-i/2-1];
				if(j<i)
					f2[t+j/2]=min(f2[t+j/2],f2[t-i+j/2]+a[i]-a[i-1]);
			}
		}
		ans=f2[n/2*(n/2+1)+(n&1)*(n/2+1)+n%K/2];
	}
	printf("%I64d\n",ans);
	return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5050][5050];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A+1) foru(j,0,B+1) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        int u = i*(m+1) + j*m;
        ll t;
        t = (ll)d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;
        t = (ll)d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5002][5002];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A+1) foru(j,0,B+1) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        int u = i*(m+1) + j*m;
        ll t;
        t = (ll)d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;
        t = (ll)d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[6000][6000];

main() {
    ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A) foru(j,0,B) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        ll t,u = i*(m+1) + j*m;

        t = d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;

        t = d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5050][5050];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    ll n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A+1) foru(j,0,B+1) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        ll t,u = i*(m+1) + j*m;

        t = (ll)d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;

        t = (ll)d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[300002];
    ll d[5002][5002];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A) foru(j,0,B) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        int u = i*(m+1) + j*m;
        ll t;
        if (i<A) {
            t = (ll)d[i][j] + a[u+m+1] - a[u+1];
            if (t < d[i+1][j]) d[i+1][j] = t;
        }
        if (j<B) {
            t = (ll)d[i][j] + a[u+m] - a[u+1];
            if (t < d[i][j+1]) d[i][j+1] = t;
        }
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5002][5002];

main() {
    ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A) foru(j,0,B) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        ll t,u = i*(m+1) + j*m;

        t = d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;

        t = d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5050][5050];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A) foru(j,0,B) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        int u = i*(m+1) + j*m;
        ll t;
        if (i<A) {
            t = (ll)d[i][j] + a[u+m+1] - a[u+1];
            if (t < d[i+1][j]) d[i+1][j] = t;
        }
        if (j<B) {
            t = (ll)d[i][j] + a[u+m] - a[u+1];
            if (t < d[i][j+1]) d[i][j+1] = t;
        }
    }

    cout<<d[A][B];

    return 0;
}


/// The Budweiser ///
#include <bits/stdc++.h>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll inf = 1e15+9;
const double pi = M_PI;
const double ep = 1e-9;

    ll a[500000];
    ll d[5005][5005];

main() {
    //ios::sync_with_stdio(false);
    //freopen("in.in","r",stdin); freopen("ou.ou","w",stdout);

    int n,k,m,A,B;

    cin>>n>>k;
    foru(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    m = n/k;
    A = n%k;
    B = k-A;
    foru(i,0,A) foru(j,0,B) d[i][j] = inf;
    d[0][0]=0;
    foru(i,0,A) foru(j,0,B) {
        ll t,u = i*(m+1) + j*m;

        t = (ll)d[i][j] + a[u+m+1] - a[u+1];
        if (t < d[i+1][j]) d[i+1][j] = t;

        t = (ll)d[i][j] + a[u+m] - a[u+1];
        if (t < d[i][j+1]) d[i][j+1] = t;
    }

    cout<<d[A][B];

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<memory.h>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<sstream>
#include<cstring>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 322000

#define TASK "1"

using namespace std;
typedef pair<int,int> pt;

int n, k;
int a[N];
int dp[5055][5055];

long long su[N];

int main(){
//	freopen(TASK".in","r",stdin);
//	freopen(TASK".out","w",stdout);
	cin >> n >> k;
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);

	int sz = n / k;

	int B = n % k;
	int A = k - B;

	for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) dp[i][j] = 2e9 + 1;
	dp[0][0] = 0;

	su[0] = 0;
	for (int i = 1; i < n; i++) su[i] = su[i - 1] + a[i] - a[i - 1];

	for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) {
		int x = (i + j) * sz + j;

		if (i < A) {
			long long t = dp[i][j] + su[x + sz - 1] - su[x];
			dp[i + 1][j] = min(dp[i + 1][j] * 1ll, t);
		}
		if (j < B) {
			long long t = dp[i][j] + su[x + sz] - su[x];
			dp[i][j + 1] = min(dp[i][j + 1] * 1ll, t);
		}
	}
	cout << dp[A][B] << endl;
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63);
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(62);
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	/*for (alpha = 2*k; alpha > 0; alpha --)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			if (beta > 0)
				break ;
		}
	}*/
	beta = n % k;
	alpha = k - beta;
	//if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

int n, k;
int A[600100];
int* DP[301000];
int a;

int f(int alpha, int beta, int idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	int alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha < k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (int i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new int[beta+2];
		memset(DP[i], -1, sizeof(DP[i]));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

int n, k;
int A[600100];
int DP[6000][6000];
int a;

int f(int alpha, int beta, int idx)
{
	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	memset(DP, -1, sizeof(DP));
	scan(A, 0, n);
	sort(A, A + n);

	int alpha, beta;
	a = n / k;
	for (alpha = 1; alpha < k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);
	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 2*k; alpha > 0; alpha --)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			if (beta > 0)
				break ;
		}
	}
	//alpha = n / a;
	//beta = n % a;
	//if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

int n, k;
int A[600100];
int* DP[301000];
int a;

int f(int alpha, int beta, int idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	int alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);

	for (int i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new int[beta+2];
		memset(DP[i], -1, sizeof(int) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	if (n == 10002)
	{
	deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = n/a; alpha >= 0; alpha --)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = k; alpha > 0; alpha --)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//alpha = n / a;
	//beta = n % a;
	//if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	/*for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}*/
	alpha = n / a;
	beta = n % a;
	if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	/*for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}*/
	alpha = n / a;
	beta = n % a;
	if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = calloc(beta+2, sizeof(long long));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 1; alpha <= k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	if (n == 10002)
	{
	deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

int n, k;
int A[600100];
int DP[6000][6000];
int a;

int f(int alpha, int beta, int idx)
{
	while(alpha >= 6000);
	while(beta >= 6000);

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	memset(DP, -1, sizeof(DP));
	scan(A, 0, n);
	sort(A, A + n);

	int alpha, beta;
	a = n / k;
	for (alpha = 1; alpha < k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);
	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>

#define deb(x) cerr << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

int n, k;
int A[600100];
int DP[6000][60000];
int a;

int f(int alpha, int beta, int idx)
{
	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = 1 << 30;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta)
		{
			DP[alpha][beta] = min(DP[alpha][beta], A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1));
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	memset(DP, -1, sizeof(DP));
	scan(A, 0, n);
	sort(A, A + n);

	int alpha, beta;
	a = n / k;
	for (alpha = 1; alpha < k; alpha ++)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//deb(a) deb(alpha); deb(beta);
	cout << f(alpha, beta, 0) << endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <list>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <ctype.h>

#define deb(x) cout << #x << " = " << x << endl;
#define print(Z,a,b) for (int __z = a; __z < b; __z ++) cout << Z[__z] << " ";
#define scan(Z,a,b) for (int __z = a; __z < b; __z ++) cin >> Z[__z];
#define bit(_z) (1ll << (_z))
#define rep(__z,__Z) for(int __z = 0; __z < __Z ; __z++ )
#define all(__z) __z.begin(),__z.end()

#define par pair<int, int>
#define p1 first
#define p2 second

#define eps = 1e-6

using namespace std;

long long n, k;
long long A[600100];
long long* DP[301000];
long long a;

long long f(long long alpha, long long beta, long long idx)
{

	if (alpha == 0 and beta == 0)
		return 0;
	if (DP[alpha][beta] == -1)
	{
		DP[alpha][beta] = bit(63)-1;
		if (alpha)
			DP[alpha][beta] = A[idx + a-1] - A[idx] + f(alpha-1, beta, idx+a);
		if (beta and DP[alpha][beta] > A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1))
		{
			DP[alpha][beta] = A[idx + a] - A[idx] + f(alpha, beta-1, idx+a+1);
		}
	}
	return DP[alpha][beta];
}

int main()
{
	cin >> n >> k;
	scan(A, 0, n);
	sort(A, A + n);

	long long alpha, beta = 0;
	a = n / k;
	for (alpha = 2*k; alpha > 0; alpha --)
	{
		if (((n - alpha * a)%(a+1)) == 0)
		{
			//deb((n - alpha * a) / (a+1))
			beta = (n - alpha * a) / (a+1);
			break ;
		}
	}
	//alpha = n / a;
	//beta = n % a;
	//if (n == 10002)
	{
	//deb(a) deb(alpha); deb(beta);
	}

	for (long long i = 0; i <= alpha+1; i ++)
	{
		DP[i] = new long long[beta+2];
		memset(DP[i], -1, sizeof(long long) * (beta+2));
	}

	cout << f(alpha, beta, 0) << endl;

	return 0;
}