#include <bits/stdc++.h>
using namespace std;
long long N, C;
long long dist(long long a, long long b) {
  long long c = abs(a - b);
  return min(c, N - c);
}
long long solve(vector<long long> x, vector<long long> v) {
  long long ans = 0;
  map<long long, long long> mp;
  long long sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    sum += v[i];
    long long dist = C - x[i];
    mp[i] = sum - dist * 2LL;
    if (i + 1 < N) mp[i] = max(mp[i], mp[i + 1]);
  }
  sum = 0;
  for (int i = 0; i < N; i++) {
    sum += v[i];
    ans = max(ans, sum + mp[i + 1] - x[i]);
    ans = max(ans, sum - x[i]);
  }
  return ans;
}
int main() {
  cin >> N >> C;
  vector<long long> x(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
    x[i] %= C;
  }
  long long fi = solve(x, v);
  vector<pair<long long, long long> > tmp;
  for (int i = 0; i < N; i++) {
    tmp.push_back(pair<long long, long long>((C - x[i]) % C, v[i]));
  }
  sort(tmp.begin(), tmp.end());
  vector<long long> nx = x, nv = v;
  for (int i = 0; i < N; i++) {
    nx[i] = tmp[i].first;
    nv[i] = tmp[i].second;
  }
  long long se = solve(nx, nv);
  cout << fi << ' ' << se << endl;
  cout << max(fi, se) << endl;
  return 0;
}
