{$APPTYPE CONSOLE}
uses math;
const maxn=1002;
var ntot,mx,k,n:longint;
    se,way,p,id,a,b,c:array[1..maxn] of longint;
    q:array[1..maxn,1..maxn] of longint;

procedure readdata;
var i:longint;
begin
 read(n);
 ntot:=n;
 for i:=1 to n do
 read(a[i],b[i]);
end;

procedure swap(var a,b:longint);
var t:longint;
begin
 t:=a;a:=b;b:=t;
end;

function less(a1,b1,a2,b2:longint):boolean;
begin
 less:=(a1<a2) or (a1=a2) and (b1>b2);
end;

procedure qsort(l,r:longint);
var xb,i,j,x:longint;
begin
 if l<r then
  begin
   i:=l;j:=r;
   x:=a[(l+r) shr 1];
   xb:=b[(l+r) shr 1];
   repeat
    while less(a[i],b[i],x,xb) do i:=i+1;
    while less(x,xb,a[j],b[j]) do j:=j-1;
    if i<=j then
     begin
      swap(a[i],a[j]);
      swap(b[i],b[j]);
      swap(id[i],id[j]);
      i:=i+1;j:=j-1;
     end;
   until i>j;
   qsort(l,j);
   qsort(i,r);
  end;
end;

procedure solve;
var n2,t,j,i,last:longint;
begin
 for i:=1 to n do
 id[i]:=i;
 n2:=0;
 for i:=1 to n do
 if a[i]+b[i]<n then
  begin
   n2:=n2+1;
   a[n2]:=a[i];
   b[n2]:=b[i];
   id[n2]:=id[i];
  end;
 n:=n2;
 qsort(1,n);
 k:=0;
 last:=0;
 for i:=1 to n do
 if (i=n) or (a[i]<>a[i+1]) or (b[i]<>b[i+1]) then
  begin
   k:=k+1;
   a[k]:=a[i];
   b[k]:=b[i];
   c[k]:=i-last;
   for j:=last+1 to i do
   q[k,j-last]:=id[j];
   last:=i;
  end;
 fillchar(p,sizeof(p),0);
 for i:=1 to k do
 for j:=i+1 to k do
 if (b[i]+a[j]>=ntot) and (a[j]>a[i]) and (b[j]<b[i]) and (p[j]<p[i]+min(a[j]-a[i],c[i]))  then
  begin
   p[j]:=p[i]+min(a[j]-a[i],c[i]);
   way[j]:=i;
  end;
 mx:=0;
 for i:=1 to k do
 if p[i]+max(0,min(ntot-a[i]-b[i],c[i]))>mx then
  begin
   mx:=p[i]+max(0,min(ntot-a[i]-b[i],c[i]));
   j:=i;
  end;
 fillchar(se,sizeof(se),0);
 if mx=0 then
  exit;
 for i:=1 to max(0,min(ntot-a[j]-b[j],c[j])) do
 se[q[j,i]]:=1; 
 while p[j]>0 do
 begin
  i:=way[j];
  for t:=1 to p[j]-p[i] do
  se[q[i,t]]:=1;
  j:=i; 
 end;
end;

procedure outdata;
var i:longint;
begin
 write(ntot-mx);
 for i:=1 to ntot do
 if se[i]=0 then
  write(' ',i);
 writeln; 
end;

begin
 assign(input,'joke.in');
 reset(input);
 assign(output,'joke.out');
 rewrite(output);
 readdata;
 solve;
 outdata;
 close(output);
end.
