#![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];
    const M: usize = 4; // max(w) - min(w) + 1
    let mut u = vec![Vec::<i32>::new(); M];
    for i in 0..N {
        u[w[i] - w0].push(v[i]);
    }
    let mut acc = vec![vec![0]; M];
    for i in 0..M {
        u[i].sort_by(|x, y| y.cmp(x));
        for j in 0..u[i].len() {
            let x = acc[i][j] + u[i][j];
            acc[i].push(x);
        }
    }
    let mut result = 0;
    for i0 in 0..u[0].len() + 1 {
        for i1 in 0..u[1].len() + 1 {
            for i2 in 0..u[2].len() + 1 {
                for i3 in 0..u[3].len() + 1 {
                    let weight = i0 * (w0 + 0) + i1 * (w0 + 1) + i2 * (w0 + 2) + i3 * (w0 + 3);
                    if weight <= W {
                        let value = acc[0][i0] + acc[1][i1] + acc[2][i2] + acc[3][i3];
                        result = std::cmp::max(result, value);
                    }
                }
            }
        }
    }
    println!("{}", result);
}

#[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: 4352