import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); // dp[i][j]は荷物iまでから容量がj以下となるように選んだ時の価値の総和の最大値を表す int[][] dp = new int[N][100001]; int[] v = new int[N]; int[] w = new int[N]; for(int i = 0; i < N; i++) { v[i] = sc.nextInt(); w[i] = sc.nextInt(); } int V = sc.nextInt(); for(int j = w[0]; j < 100001; j++) { dp[0][j] = v[0]; } for(int i = 1; i < N; i++) { for(int j = 1; j < 100001; j++) { if(j >= w[i]) { dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); } else { dp[i][j] = dp[i - 1][j]; } } } int min = 0; int max = 0; for(int j = 1; j < 100001; j++) { if(dp[N - 1][j] == V) { min = j; break; } } for(int j = 1; j < 100001; j++) { if(dp[N - 1][j] > V) { max = j - 1; break; } } System.out.println(min); if(max == 0) { System.out.println("inf"); } else { System.out.println(max); } } }