public B176() {
    Scanner in = new Scanner(System.in);

    StringTokenizer st;
    Book[] books = new Book[Integer.parseInt(in.nextLine())];

    int thickness = 0;

    for (int x = 0; x < books.length; x++) {
      st = new StringTokenizer(in.nextLine());
      books[x] = new Book(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
      thickness += books[x].thickness;
    }

    Arrays.sort(books);

    int width = 0;

    // for(int x = 0; x < books.length; x++)
    // {
    // System.out.println(books[x].width + " " + books[x].thickness);
    // }

    for (int x = 0; x < books.length; x++) {
      if (thickness - width - books[x].thickness >= books[x].width) {
        width += books[x].width;
        thickness -= books[x].thickness;
      }
    }

    System.out.println(thickness);
  }