#include "bits/stdc++.h" #define rep(a,b) for(int a = 0;a < b;a++) #define REP(i, x, n) for(int i = x; i < n; i++) #define P(a) cout << a << endl using namespace std; typedef long long ll; typedef unsigned long long ull; int dx[] = { 1, -1 , 0 , 0 }; int dy[] = { 0, 0, 1, -1 }; ll MOD = 1000000007; unsigned long long str_to_int(std::string str) { unsigned long long ret; std::stringstream ss; ss << str; ss >> ret; return ret; } int main() { int n,V,sum = 0; cin >> n; vector v(n), w(n); rep(i, n) { cin >> v[i] >> w[i]; sum += w[i]; } cin >> V; vector dp(sum+1, -1); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum; j >= 0; j--) { if (dp[j] != -1) { dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]); } } } int buf; rep(i, sum + 1) { if (dp[i] != -1) { buf = dp[i]; } else { dp[i] = buf; } } int minans = 1e9, maxans = -1; for (int i = 1; i <= sum; i++) { if (dp[i] == V) { maxans = max(maxans, i); minans = min(minans, i); } } P(minans); if (dp[sum] == V) { P("inf"); } else { P(maxans); } }