import java.io.*;
import java.util.*;

public class elect_is_stupid implements Runnable {
    private static final String FILENAME = elect_is_stupid.class.getName().substring(0, elect_is_stupid.class.getName().indexOf('_'));
    
    File inFile = new File(FILENAME + ".in");
    PrintWriter out;
    BufferedReader in;

    private StringTokenizer st;

    elect_is_stupid() {     
        try {
            in = new BufferedReader(new FileReader(inFile));
            st = new StringTokenizer(in.readLine());
            out = new PrintWriter(new File(FILENAME + ".out"));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(239);           
        }       
    }
    
    int nextInt() throws IOException {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }
    
    class C implements Comparator<Integer> {
    	int[] v;
    	C(int[] v) {
    		this.v = v;
    	}
		public int compare(Integer o1, Integer o2) {
			return v[o2] - v[o1];
		}
    }
    
    
    public void run() {
        try {
            int n = nextInt();
            int i;
            int[] vi = new int[n];
            int[] pi = new int[n];
            int min = 0;
            for (i = 0; i < n; i++) {            	
            	vi[i] = nextInt();
            	pi[i] = nextInt();
            	if (pi[i] == -1)
            		min = Math.max(min, vi[i]);
            }
            
            
            int res = Integer.MAX_VALUE;
            int resi = -1;
            
            for (int t = 0; t < n; t++) {
            	int[] v = vi.clone();
            	int[] p = pi.clone();
            	int r = p[t];
            	if (r == -1) {
            		continue;
            	}
            	TreeSet<Integer> s = new TreeSet<Integer>();
            	for (i = 0; i < n; i++)
            		if (i != t)
            			s.add(v[i]);
            	int c = v[t];
            	while (true) {
            		int z = s.last();
            		if (z < c)
            			break;
            		s.remove(z);
            		s.add(z - 1);
            		c++;
            		r++;
            	}
            	if (r < res) {
            		res = r;
            		resi = t;
            	}
            }
            
            out.println(res);
            out.println(resi + 1);
        } catch (IOException e) {
			e.printStackTrace();
		} finally {
            out.close();
        }
        
                
    }
    
    public static void main(String[] args) {
        new Thread(new elect_is_stupid()).start();
    }

}
