// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {

r#"3 8
3 3
4 5
5 6"# => r#"9"#,

r#"3 8
3 30
4 50
5 60"# => r#"90"#,

r#"1 1000000000
1000000000 10"# => r#"10"#,

r#"6 15
6 5
5 6
6 4
6 6
3 5
7 2"# => r#"17"#,
}

const INF:usize = 1 << 60;

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize, w: usize,
        wv: [(usize, usize); n],

    }

    // const MAX_VALUE:usize = 30;
    const MAX_VALUE:usize = 100100;
    // let mut dp = vec![vec![0; MAX_VALUE]; 5];
    let mut dp = vec![vec![INF; MAX_VALUE]; n + 1];
    dp[0][0] = 0;

    for i in 0..n {
        for j in 0..MAX_VALUE {
            if wv[i].1 <= j {
                dp[i + 1][j] = std::cmp::min(dp[i + 1][j], dp[i][j - wv[i].1] + wv[i].0);
            }
            dp[i + 1][j] = std::cmp::min(dp[i + 1][j], dp[i][j]);
        }
    }

    // println!("{:?}", dp[n]);
    // println!("{:?}", ( 0..MAX_VALUE ).map(|x| x).collect::<Vec<_>>());

    let max_weight = dp[n][(0..MAX_VALUE).filter(|&x| dp[n][x] <= w).max().unwrap_or(0)];
    (0..MAX_VALUE).filter(|&x| dp[n][x] == max_weight).max().unwrap().to_string()
}

Measured memory_bytes: 106748