program test
implicit none

integer(8) :: honsuu(9) = (/ 2,5,5,4,5,6,3,7,6 /),mojisuu(9)=0
integer(8) :: n,m,a(9)=0,b(9)=0,count,i,j,k,char,final
integer(8) :: aa(9),bb(9),aaa(9)=0,bbb(9)=0,ccc(9)=0,char_shou,char_amari,free,flag
integer(8) :: kotae(10000)

read(*,*) n,m
read(*,*) (a(i),i=1,m)

do i=1,m
	b(i) = honsuu(a(i))
enddo

if(m == 1)then
	aaa(1) = a(1)
	ccc(1) = n/b(1)
	count = 1
else
	call heapsort_up(m,b(1:m),a(1:m))

	bb(1) = b(1)
	aa(1) = a(1)
	count = 1

	do i=2,m
		if(b(i) == bb(count)) then
			if(a(i) > aa(count) )then
				aa(count) = a(i)
			else
				continue
			endif
		else
			count = count + 1
			bb(count) = b(i)
			aa(count) = a(i)
		endif
	enddo

	char_shou = int(n/bb(1))
	char_amari = mod(n,bb(1))

	aaa(1:count) = aa(1:count)
	bbb(1:count) = bb(1:count)

	call heapsort_up(count-1,aaa(2:count),bbb(2:count))
	!数字が小さい方が前

	if(char_amari == 0) then
		ccc(1) = char_shou
		ccc(2:count) = 0
	else
		free = 1
		do
			!2文字目からcount文字目までを、合計free文字になるように探査
			ccc(1) = int(n/bb(1)) - free
			ccc(2:count) = 0
			
			do
				!文字数チェック
				char = 0
				do i=1,count
					char = char + bbb(i) * ccc(i)
				enddo
				
				if(char == n .and. sum(ccc(2:count)) == free ) then
					goto 200
				endif
				
				ccc(count) = ccc(count) + 1
				do i=count,3,-1
					if(ccc(i) > free) then
						ccc(i) = 0
						ccc(i-1) = ccc(i-1) + 1
					endif
				enddo
				
				if(ccc(2) > free)then
					free = free + 1
					ccc(1) = char_shou - free
					ccc(2:count) = 0
				endif
				
			enddo
			
		enddo
	endif

	200 continue

	!最後にソート
	call heapsort_down(count,aaa(1:count),ccc(1:count))
	
endif


final = 0

do i=1,count
	do j=1,ccc(i)
		final = final + 1
		kotae(final) = aaa(i)
	enddo
enddo

write(*,'(10000(I1))') (kotae(i),i=1,final)

contains
 
subroutine heapsort_down(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) > y1(j+1)) j = j+1
				endif
				
				if (t1 > y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_down
 
subroutine heapsort_up(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_up


end program
