program march;
        uses crt;
        type
            zadad=2..1999;
            zadad2=0..2000;
            sl=0..1020847;
        var
           n,p:zadad;
           i:sl;
           j,br:longint;
           l:zadad2;
           a:array[1..2000] of zadad2;
        function factoriel(s:zadad):longint;
                 begin
                      if s=1 then factoriel:=1 else
                      factoriel:=s*factoriel(s-1);
                 end;
        procedure izravnqvane;
                  begin
                       for l:= n-1 downto 1 do
                       if a[l] > a[l+1] then a[l]:=a[l+1];
                  end;
        function dovejda(p:zadad2):boolean;
                 var
                    q:zadad2;
                 begin
                      q:=1;
                      for l:= 1 to n-1 do
                          if not a[l] = a[l+1] then q:=q+1;
                      if q=p then dovejda:=true;
                 end;
        procedure proizvolnost;
                  var
                     i,j,p:zadad2;
                     k:boolean;
                  begin
                       for i:= 1 to n do begin
                           repeat
                           p:=random(n);
                           if i>1 then begin j:=0; repeat
                              j:=j+1;
                              if a[j]<> p then k:=true else k:=false;
                           until (k=false) or (j=i-1);
                           end;
                           if i<n then begin j:=i;
                              repeat
                                 j:=j+1;
                                 if a[j]<> p then k:=true else k:=false;
                              until (k=false) or (j=n);
                           end;
                           if k=true then a[i]:=p;
                           until k=true;
                       end;
                  end;
        begin
             clrscr;
             Write('Vhod: ');Read(n,p);
             for j:= 1 to factoriel(n) do begin
                 RandSeed:=j;
                 proizvolnost;
                 izravnqvane;
                 if dovejda(p) then i:=i+1;
                 if i=1020847 then begin
                    br:=br+1;
                    i:=0;
                 end;
             end;
             Writeln('Izhod: ',br);
             readln(br);
        end.