const
 maxn=1000+10;

var
 n:integer;
 num:array[0..maxn,0..maxn]of integer;
 f,prev:array[0..maxn]of integer;
 ts:array[0..maxn-1,0..1]of integer;

procedure readin;
 var
  i:integer;
  a,b:integer;
 begin
  fillchar(num,sizeof(num),0);
  readln(n);
  for i:=0 to n-1 do begin
   readln(a,b);
   inc(num[a,n-b]);
   ts[i,0]:=a; ts[i,1]:=n-b;
  end;
 end;

procedure solve;
 var
  a,b:integer;
  mf,cf:integer;
 begin
  f[0]:=0; prev[0]:=0;
  for a:=1 to n do begin
   mf:=0;
   for b:=0 to a-1 do begin
    if(num[b,a]>a-b)then cf:=f[b]+a-b
    else cf:=f[b]+num[b,a];
    if(mf<cf)then begin
     mf:=cf;
     prev[a]:=b;
    end;
   end;
   f[a]:=mf;
  end;
 end;

procedure goback;
 var
  ca,b:integer;
 begin
  ca:=n;
  while(ca>0)do begin
   b:=prev[ca];
   dec(num[b,ca],ca-b);
   if(num[b,ca]<0)then num[b,ca]:=0;
   ca:=b;
  end;
 end;

procedure writeout;
 var
  i,j:integer;
  l,r:integer;
 begin
  write(n-f[n]);
  for i:=0 to n-1 do begin
   if(num[ts[i,0],ts[i,1]]>0)then begin
    write(' ',i+1);
    dec(num[ts[i,0],ts[i,1]]);
   end;
  end;
  writeln;
 end;

begin
 assign(input,'joke.in'); reset(input);
 assign(output,'joke.out'); rewrite(output);
 readin;
 solve;
 goback;
 writeout;
 close(output);
 close(input);
end.