import random
import sys

MAXN = int(sys.argv[1])
MAXA = int(sys.argv[2])

def generate(i, d):
    ans = [random.randint(1, MAXA-1)]
    for j in xrange(i-1):
        if d == -1:
            ans.append(random.randint(0, ans[-1]))
        else:
            ans.append(random.randint(ans[-1], MAXA))
        d = -d
    return ans

N = random.randint(max(1, MAXN * 9 / 10), MAXN)
print N
tmp = []
while sum(tmp) < N:
    tmp.append(random.randint(1, N - sum(tmp)))
toprint = []
for i in tmp:
    if len(toprint) <= 1 or toprint[-1] > toprint[-2]:
        toprint += generate(i, -1)
    else:
        toprint += generate(i, 1)


print ' '.join(map(str, toprint))
