while 1: I=raw_input().split();C=map(int,I[1:]);i=0;b=[""] while i<int(I[0][:-1]):i+=1;t=[`c`+" "+b[i-c]for c in C if i>=c and"- "!=b[i-c]];b+=[t and min(t,key=len)or"- "] print b[i][:-1]
Note that non-ascii characters in the above source code will be escaped (such as \x9f).