
var a,ozn,d:array[0..1100000] of Longint;
    fin,fout:Text;
    n,m,i,j,k,t,res:Longint;
    ind:boolean;
begin


    Assign(fin,'podniz.in');
    reset(fin);
    Assign(fout,'podniz.out');
    rewrite(fout);

    readln(fin,n,m);




    for i:=0 to m-1 do
    begin
       readln(fin,a[i]);
       a[i]:=a[i]-1;
    end;
    fillchar(ozn, n*sizeof(a[0]), 0);


    k := 1; t := 0;
    for i := m-1 downto 0 do
    begin
        d[i] := k;
        if (ozn[a[i]]=0) then
        begin
            ozn[a[i]] := 1;
            t:=t+1;
            if (t=n) then
            begin
               fillchar(ozn, n*sizeof(a[0]), 0);
               t:=0;
               k:=k+1;
            end;
        end;
    end;

    res := k;
    writeln(fout,res);
    ind:=true;
    fillchar(ozn, n*sizeof(a[0]), 0);
    i:=0;
    while (i<m) and ind do
    begin
       if (d[i]<>k) then
       begin
           j := 0;
	   while ((j<n)and(ozn[j]>0)) do
  		j:=j+1;
	   writeln(fout,j+1);
           k:=k-1;
           if (k=0) then
             ind :=false
           else while ((i<m)and(j<>a[i])) do i:=i+1;
           fillchar(ozn, n*sizeof(a[0]), 0);
       end
       else ozn[a[i]]:=1;
       i:=i+1;
    end;

    if (k=1) then
    begin
       j := 0;
       while ((j<n)and(ozn[j]>0)) do j:=j+1;
       writeln(fout,j+1);
    end;

    close(fin);
    close(fout);
end.
