#include using namespace std; typedef long long ll; typedef vector vint; typedef pair pint; typedef vector vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=n-1;i>=(0);i--) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define all(v) (v).begin(),(v).end() #define eall(v) unique(all(v), v.end()) #define pb push_back #define mp make_pair #define fi first #define se second #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) const int MOD = 1e9 + 7; const int INF = 1e9; const ll INFF = 1e18; int N; int mi, ma; int v[110], w[110]; int V; int dp[100010]; int solve(int W){ rep(i, 100010) dp[i] = 0; for (int i = 0; i < N; ++i){ for (int j = W; j >= w[i]; --j){ chmax(dp[j], dp[j - w[i]] + v[i]); } } int ret = 0; rep(i, W + 1) chmax(ret, dp[i]); return ret; } int binary(int target){ // dp[100001] = INF; int l = 1, r = 100001; while(r - l > 2 ){ int m = (l + r) / 2; // printf("%d %d %d\n", l, r, m); auto ret = solve(m); // printf("ret %d\n", ret); if(ret < target) l = m; else r = m; } // printf("lr %d %d\n", l, r); reps(i, max(1, l - 100), min(r + 1000, 100) + 1){ // printf("i %d %d\n", i, solve(i)); if(solve(i) == target) return i; else if(solve(i) > target) return i; } return 100001; } int main(void){ cin >> N; rep(i, N) cin >> v[i] >> w[i]; cin >> V; // printf("\n"); // reps(i, 1, 11) printf("%d\n", solve(i)); // printf("\n"); int ansl = binary(V); int ansr = binary(V + 1); printf("%d\n", ansl); if(ansr == 100001) printf("inf\n"); else printf("%d\n", ansr - 1); return 0; }