/* -*- coding: utf-8 -*-
 *
 * 1858.cc:  No.1858 Gorgeous Knapsack - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 5000;
const int MAX_M = 5000;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

pii vws[MAX_N];
ll dp[MAX_M + 1];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &vws[i].first, &vws[i].second);
  sort(vws, vws + n);

  ll maxbt = 0;
  for (int i = n - 1; i >= 0; i--) {
    int vi = vws[i].first, wi = vws[i].second;

    if (wi <= m) {
      ll bt = (ll)vi * (vi + dp[m - wi]);
      maxbt = max(maxbt, bt);

      for (int j = m - wi; j >= 0; j--)
	setmax(dp[j + wi], dp[j] + vi);
    }
  }

  printf("%lld\n", maxbt);
  return 0;
}