#include <bits/stdc++.h>
using namespace std;
ifstream fin ("energii.in");
ofstream fout ("energii.out");
const int N = 5005, limit = 2e9;
int power[N / 5], cost[N / 5], d[N / 5][N];
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
fin >> n >> m;
for(int i = 1; i <= n; ++i) fin >> power[i] >> cost[i];
for(int i = 1; i <= n; ++i) {
if(power[i] >= m) cost[i] = min(cost[i], m + 1);
}
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= m + 1; ++j) {
d[i][j] = d[i - 1][j];
if(j >= cost[i]) d[i][j] = max(d[i][j], d[i - 1][j - cost[i]] + power[i]);
}
}
for(int i = 1; i <= m + 1; ++i) {
if(d[n][i] >= m) {
fout << i << "\n";
return 0;
}
}
fout << "-1";
return 0;
}