#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"def solve():\n"
"  I=lambda:map(int,input().split())\n"
"  N,W=I()\n"
"  g={}\n"
"  for _ in[0]*N:\n"
"    a,b=I()\n"
"    g[a]=g.get(a,[])+[b]\n"
"  *w,=g.keys()\n"
"  v=[]\n"
"  for i in range(len(w)):\n"
"    s=[0]+sorted(g[w[i]])[::-1]\n"
"    for i in range(1,len(s)):\n"
"      s[i]+=s[i-1]\n"
"    v.append(s)\n"
"  for _ in[0]*(4-len(w)):\n"
"    w.append(10**18)\n"
"    v.append([0])\n"
"  ans=0\n"
"  for i in range(len(v[0])):\n"
"    s0=w[0]*i\n"
"    for j in range(len(v[1])):\n"
"      s1=s0+w[1]*j\n"
"      if s1>W:break\n"
"      for k in range(len(v[2])):\n"
"        s2=s1+w[2]*k\n"
"        if s2>W:break\n"
"        l=min((W-s2)//w[3],len(v[3])-1)\n"
"        ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l])\n"
"  print(ans)\n"
"if __name__=='__main__':\n"
"  solve()\n"
"\"";
  system(s);
  return 0;
}            