#![allow(non_snake_case)]

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let N: usize = stdin.read();
    let W: usize = stdin.read();
    let (w, v): (Vec<usize>, Vec<i32>) = (0..N).map(|_| (stdin.read::<usize>(), stdin.read::<i32>())).unzip();

    let w0 = w[0];
    let w: Vec<usize> = w.into_iter().map(|x| x - w0).collect();
    const W_MAX: usize = 3;
    let W_SUM_MAX = N * W_MAX;

    let mut dp = vec![vec![vec![None; W_SUM_MAX + 1]; N + 1]; N + 1];
    for i in 0..N + 1 {
        for k in 0..W_SUM_MAX + 1 {
            dp[i][0][k] = Some(0);
        }
    }
    for i in 1..N + 1 {
        for j in 1..N + 1 {
            for k in 0..W_SUM_MAX + 1 {
                dp[i][j][k] = if w[i - 1] <= k && dp[i - 1][j - 1][k - w[i - 1]].is_some() {
                    std::cmp::max(dp[i - 1][j][k], Some(dp[i - 1][j - 1][k - w[i - 1]].unwrap() + v[i - 1]))
                } else {
                    dp[i - 1][j][k]
                };
                //println!("dp[{}][{}][{}] = {:?}", i, j, k, dp[i][j][k]);
            }
        }
    }
    let mut result = Some(0);
    for j in 1..N + 1 {
        for k in 0..W_SUM_MAX + 1 {
            if k + j * w0 <= W {
                result = std::cmp::max(result, dp[N][j][k]);
            }
        }
    }
    println!("{}", result.unwrap());
}

#[allow(dead_code, unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

Measured memory_bytes: 30972