import java.util.*; import java.io.*; public class Main { static int[][] scores; static int[][] dp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); HashMap map = new HashMap<>(); HashMap next = new HashMap<>(); map.put(0, 0); for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); for (Map.Entry entry : map.entrySet()) { int key = entry.getKey(); int value = entry.getValue(); if (!next.containsKey(key) || next.get(key) >= value + b) { next.put(key, value + b); } key += a; if (!next.containsKey(key) || next.get(key) >= value) { next.put(key, value); } } map = next; next = new HashMap<>(); } int min = Integer.MAX_VALUE; for (Map.Entry entry : map.entrySet()) { min = Math.min(min, Math.max(entry.getKey(), entry.getValue())); } System.out.println(min); } }