/*#include <iostream>
using namespace std;
ifstream cin("pavaj.in");
ofstream cout("pavaj.out");
int sp[1001][1001], n, m, k, l1, c1, l2, c2, maxim, x;
int main() {
//sp[i][j] = suma submatricei cu coltul stanga-sus in (1, 1) si
// dreapta-jos in (i, j)
cin >> n >> m >> k;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cin >> x;
sp[i][j] = sp[i-1][j] + sp[i][j-1] - sp[i-1][j-1] + x;
}
}
for(int i = 1; i <= k; i ++) {
cin >> l1 >> c1 >> l2 >> c2;
if(c2 < c1)
swap(c1, c2);
if(l2 < l1)
swap(l2, l1);
// stanga-sus (l1, c1)
// dreapta-jos (l2, c2)
int suma = sp[l2][c2] - sp[l2][c1-1] - sp[l1-1][c2] + sp[l1-1][c1-1];
if(suma == 0) { // avem doar dale deteriorate
cout << 0 << '\n';
} else if(suma == (l2 - l1 + 1) * (c2 - c1 + 1)) { // avem doar dale nedeteriorate
cout << 1 << '\n';
} else {
cout << 2 << '\n';
}
}
// sp[i] = sp[i-1] + a[i]
return 0;
}*/
/*#include <iostream>
using namespace std;
int main() {
int n, m, x, val;
cin >> n >> m >> x;
int imp= 0,pare=0,ok=0;
for (int i = 1; i <= n; i++) {
int gasit = 0;
for (int j = 1; j <= m; j++) {
cin >> val;
if (val == x) {
gasit = 1;
ok = 1;
}
}
if (gasit == 1) {
if (i % 2 != 0) {
imp++;
} else {
pare++;
}
}
}
if (ok == 0) {
cout << "nu exista";
} else if (imp >1 || pare > 1) {
cout << "DA";
} else {
cout << "NU";
}
return 0;
}
*/
/*#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("control.in");
ofstream fout("control.out");
long long a, b, c;
fin >> a >> b >> c;
long long cntb= 0;
if (b >= c) {
cntb = (b - c)/9 + 1;
}
long long cnta=0;
if ((a-1)>=c) {
cnta = ((a - 1) - c) / 9 + 1;
}
fout << cntb - cnta <<"\n";
return 0;
}
*/
/*#include <iostream>
using namespace std;
long long a[200005];
long long vizitate[200005];
int main() {
int n;
long long k;
cin >> n >> k;
for (int i= 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
vizitate[i] = -1;
}
long long cur= 1;
long long pasi= 0;
bool gasit=false;
while (pasi< k) {
if (vizitate[cur]!= -1) {
long long start= vizitate[cur];
long long len=pasi-start;
k = (k - start) % len;
gasit=true;
break;
}
vizitate[cur] =pasi;
cur= a[cur];
pasi++;
}
if(gasit==true){
pasi = 0;
while (pasi< k) {
cur= a[cur];
pasi++;
}
}
cout << cur<< "\n";
return 0;
}
*/
/*#include <iostream>
using namespace std;
int a[100005];
bool vizitat[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int buton_curent = 1,apasari=0;
while(true){
if (buton_curent == 2) {
cout << apasari << "\n";
return 0;
}
if (vizitat[buton_curent]) {
cout << -1 << "\n";
return 0;
}
vizitat[buton_curent] = true;
buton_curent = a[buton_curent];
apasari++;
}
return 0;
}
*/
/*#include <iostream>
using namespace std;
int main() {
char s[300];
char v[105][20];
int n = 0;
cin.getline(s, 300);
char cuv[20];
int l = 0;
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] != ' ') {
cuv[l] = s[i];
l++;
}
if (s[i] == ' ' || s[i + 1] == '\0') {
if (l > 0) {
cuv[l] = '\0';
int f[30] = {0};
int ok = 1;
for (int j = 0; cuv[j] != '\0'; j++) {
int poz = cuv[j] - 'a';
f[poz]++;
if (f[poz] > 1) {
ok = 0;
}
}
if (ok == 1) {
for (int j = 0; j <= l; j++) {
v[n][j] = cuv[j];
}
n++;
}
l = 0;
}
}
}
if (n == 0) {
cout << "nu exista" << endl;
} else {
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int p = 0;
while (v[i][p] != '\0' && v[j][p] != '\0' && v[i][p] == v[j][p]) {
p++;
}
if (v[i][p] > v[j][p]) {
char aux[20];
int p1 = 0;
while (v[i][p1] != '\0') {
aux[p1] = v[i][p1];
p1++;
}
aux[p1] = '\0';
int p2 = 0;
while (v[j][p2] != '\0') {
v[i][p2] = v[j][p2];
p2++;
}
v[i][p2] = '\0';
int p3 = 0;
while (aux[p3] != '\0') {
v[j][p3] = aux[p3];
p3++;
}
v[j][p3] = '\0';
}
}
}
for (int i = 0; i < n; i++) {
cout << v[i] << endl;
}
}
return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int nr_v(string s) {
int c = 0;
string voc = "aeiouAEIOU";
for (char ch : s) {
if (voc.find(ch) != string::npos) {
c++;
}
}
return c;
}
int main() {
int n;
cin >> n;
vector<string> v(n);
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
int nr = nr_v(v[i]);
if (nr > mx) {
mx = nr;
}
}
vector<string> r;
for (int i = 0; i < n; i++) {
if (nr_v(v[i]) == mx) {
r.push_back(v[i]);
}
}
sort(r.begin(), r.end());
for (string s : r) {
cout << s << " ";
}
return 0;
}
*/
/*#include <fstream>
using namespace std;
ifstream fin("control2.in");
ofstream fout("control2.out");
int f[201],v[101],k;
int main() {
int n, x;
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> x;
f[x]++;
}
for (int i = 1; i <= 200; i++) {
if (f[i] > 0) {
k++;
v[k] = f[i];
}
}
int n1= 0, n0 =0;
for (int i = 1; i + 2 <= k; i += 3) {
int a = v[i],b = v[i + 1],c = v[i + 2];
if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
n1++;
}
else if (a % 2 != 0 && b % 2 != 0 && c % 2 != 0) {
n1++;
}
else {
n0++;
}
}
int c= n1 * 10 + n0;
fout << c << "\n";
int p = 1;
if (c < 2) {
p = 0;
} else {
for (int d = 2; d <= c / 2; d++) {
if (c % d == 0) {
p = 0;
break;
}
}
}
fout<<p <<"\n";
return 0;
}
*/
/*#include <bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream cin("cod.in");
ofstream cout("cod.out");
int rest[16];
int main() {
int p,n;
cin>>p>>n;
int nr_nefol=0,parolai=0,parolag=0;
char c;
int i=1;
while(cin>>c){
if(c>='0'&&c<='9'){
int cif=c-'0';
for(int d=2;d<=15;d++){
rest[d]=(rest[d]*10+cif)%d;
}
}
else if(c=='#'){
if(p==1){
bool div=false;
for(int d=2;d<=15;d++){
if(rest[d]==0)
div=true;
}
if(div==false)
nr_nefol++;
}
else if(p==2){
for(int d=2;d<=9;d++){
if(rest[d]==0)
parolai++;
}
}
else if(p==3){
for(int d=10;d<=15;d++){
if(rest[d]==0)
parolag++;
}
}
for(int d=2;d<=15;d++){
rest[d]=0;
}
}
}
if(p==1){
bool div=false;
for(int d=2;d<=15;d++){
if(rest[d]==0)
div=true;
}
if(div==false)
nr_nefol++;
}
else if(p==2){
for(int d=2;d<=9;d++){
if(rest[d]==0)
parolai++;
}
}
else if(p==3){
for(int d=10;d<=15;d++){
if(rest[d]==0)
parolag++;
}
}
if(p==1)cout<<nr_nefol<<"\n";
if(p==2)cout<<parolai<<"\n";
if(p==3)cout<<parolag<<"\n";
return 0;
}
*/
/*#include <iostream>
#include <vector>
#include <queue>
using namespace std;
void tufftufftuff() {
int n;
cin >> n;
vector<int> a(n + 1, 0);
priority_queue<pair<int, int>> coada;
coada.push({n, -1});
for (int i = 1; i <= n; i++) {
int lungime = coada.top().first;
int l = -coada.top().second;
coada.pop();
int r=l+lungime-1,mij;
if (lungime%2 != 0) {
mij=(l+ r)/2;
} else {
mij=(l+r-1)/2;
}
a[mij]=i;
if (l<=mij-1) {
int lungime_stanga =(mij- 1) -l+ 1;
coada.push({lungime_stanga,-l});
}
if (mij+1<= r) {
int lungime_dreapta =r- (mij+1)+ 1;
coada.push({lungime_dreapta,-(mij+ 1)});
}
}
for (int i=1;i<=n;i++) {
cout <<a[i]<< " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
tufftufftuff();
}
return 0;
}
*/
/*#include <iostream>
#include <fstream>
using namespace std;
int p, n, k;
char m[205][205];
int x1[40005], y11[40005], x2[40005], y2[40005], nr;
int pN, pE, pS, pV;
int main() {
ifstream f("robotel.in");
ofstream g("robotel.out");
f >> p >> n >> k;
for (int i = 1; i <= k; i++) {
int x, y;
char ch;
f >> x >> y >> ch;
m[x][y] = ch;
}
if (p == 1) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (m[i][j] == 'E') {
for (int pas = j + 1; pas <= n; pas++) {
if (m[i][pas] != 0) {
if (m[i][pas] == 'V') {
nr++;
x1[nr] = i; y11[nr] = j;
x2[nr] = i; y2[nr] = pas;
}
break;
}
}
}
if (m[i][j] == 'S') {
for (int pas = i + 1; pas <= n; pas++) {
if (m[pas][j] != 0) {
if (m[pas][j] == 'N') {
nr++;
x1[nr] = i; y11[nr] = j;
x2[nr] = pas; y2[nr] = j;
}
break;
}
}
}
}
}
if (nr == 0) {
g << 0;
}
for (int i = 1; i <= nr; i++) {
g << x1[i] << " " << y11[i] << " " << x2[i] << " " << y2[i] << "\n";
}
} else {
int x = 1, y = 1;
char ch = 'E';
int semnalizator = 0;
int gata = 0;
if (m[1][1] != 0) {
ch = m[1][1];
semnalizator = 1;
}
while (gata == 0) {
if (ch == 'N') {
if (x == 1) gata = 1;
else { x--; pN++; }
} else if (ch == 'E') {
if (y == n) gata = 1;
else { y++; pE++; }
} else if (ch == 'S') {
if (x == n) gata = 1;
else { x++; pS++; }
} else {
if (y == 1) gata = 1;
else { y--; pV++; }
}
if (gata == 0 && m[x][y] != 0) {
if (semnalizator == 1 && ch == 'E' && m[x][y] == 'V') gata = 1;
else if (semnalizator == 1 && ch == 'V' && m[x][y] == 'E') gata = 1;
else if (semnalizator == 1 && ch == 'S' && m[x][y] == 'N') gata = 1;
else if (semnalizator == 1 && ch == 'N' && m[x][y] == 'S') gata = 1;
else {
ch = m[x][y];
semnalizator = 1;
}
}
}
g << pN << " " << pE << " " << pS << " " << pV;
}
return 0;
}
*/
/*#include <fstream>
using namespace std;
ifstream f("faleza.in");
ofstream g("faleza.out");
int n, sus[100005], jos[100005];
int main() {
f >> n;
for (int i = 1; i <= n; i++) {
f >> sus[i];
}
for (int i = 1; i <= n; i++) {
f >> jos[i];
}
int a = 0, b = 0;
for (int i = 1; i <= n; i++) {
int cs = 1 - sus[i];
int cj = 1 - jos[i];
int na = a + cs;
int nb = b + cj;
a = min(na, nb + cs);
b = min(nb, na + cj);
}
g << min(a, b);
return 0;
}
*/
/*#include <fstream>
#include <string>
using namespace std;
ifstream f("peste.in");
ofstream g("peste.out");
int p, n, nr[10][10];
string v[105];
int main()
{
f >> p >> n;
for (int k = 1; k <= n; k++)
{
string s;
f >> s;
string maxim = "";
int a = 0, b = 0;
for (int i = 0; i < s.size() - 1; i++)
{
string t = "";
for (int j = 0; j < s.size(); j++)
{
if (j != i && j != i + 1)
{
t = t + s[j];
}
}
if (t > maxim)
{
maxim = t;
a = s[i] - '0';
b = s[i + 1] - '0';
}
}
v[k] = maxim;
if (a < b)
{
nr[a][b]++;
}
else
{
nr[b][a]++;
}
}
if (p == 1)
{
int rez = 0;
for (int i = 0; i <= 9; i++)
{
for (int j = 0; j <= 9; j++)
{
if (nr[i][j] > rez)
{
rez = nr[i][j];
}
}
}
g << rez;
}
else
{
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (v[i] + v[j] < v[j] + v[i])
{
string aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
for (int i = 1; i <= n; i++)
{
g << v[i];
}
}
return 0;
}
*/
/*#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("faleza.in");
ofstream fout("faleza.out");
int a[2][100005], n, cnt = 0;
int main()
{
fin >> n;
for (int i = 1; i <= n; i ++)
{
fin >> a[0][i];
}
for (int i = 1; i <= n; i ++)
{
fin >> a[1][i];
}
bool putemAlege = true;
int linie = 0;
for (int i = 1; i <= n; i ++)
{
if (a[0][i] == 0 && a[1][i] == 0)
{
cnt ++;
}
else
{
if (putemAlege == true) {}
else
{
if (linie == 0 && a[0][i] == 0)
{
cnt ++;
}
if (linie == 1 && a[1][i] == 0)
{
cnt ++;
}
}
if (a[0][i] == 1 && a[1][i] == 1)
{
putemAlege = true;
}
else if (putemAlege == true)
{
if (a[0][i] == 1)
{
putemAlege = false;
linie = 0;
}
else if (a[1][i] == 1)
{
putemAlege = false;
linie = 1;
}
}
}
}
fout << cnt;
return 0;
}
*/
/*#include <fstream>
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
int main()
{
int m, n, d, l;
fin >> m >> n;
fin >> d >> l;
int maxplus = l + d;
int maxminus = l - d;
int rez = 0;
for (int i = 2; i <= n; i++)
{
fin >> d >> l;
if (l - d + maxplus > rez)
{
rez = l - d + maxplus;
}
if (l + d + maxminus > rez)
{
rez = l + d + maxminus;
}
if (l + d > maxplus)
{
maxplus = l + d;
}
if (l - d > maxminus)
{
maxminus = l - d;
}
}
fout << rez;
return 0;
}
*/
#include <fstream>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int t[2005], p[2005];
int cnt[1505];
int main()
{
int n, c;
fin >> n >> c;
for (int i = 1; i <= n; i++)
{
fin >> t[i] >> p[i];
}
long long rez = 0;
for (int j = 1; j <= n; j++)
{
for (int x = 0; x <= 1500; x++)
{
cnt[x] = 0;
}
for (int i = 1; i <= n; i++)
{
if (p[i] >= p[j])
{
cnt[t[i]]++;
}
}
long long s = 0;
for (int x = 0; x <= 1500; x++)
{
long long v = 1LL * cnt[x] * p[j] - c;
if (s < 0)
{
s = v;
}
else
{
s = s + v;
}
if (s > rez)
{
rez = s;
}
}
}
fout << rez;
return 0;
}