#include void chmin(int* a, int b) { if (*a > b) *a = b; } void chmax(int* a, int b) { if (*a < b) *a = b; } int main() { int i, N, D, P[1001], Q[1001]; scanf("%d %d", &N, &D); for (i = 1; i <= N; i++) scanf("%d %d", &(P[i]), &(Q[i])); int j, k, ans = -(1 << 30), tmp, tmpp; for (i = 1; i <= N; i++) { for (j = 1; j <= N; j++) { if (j == i) continue; tmp = Q[i] + Q[j] - P[i] - P[j]; if (tmp >= 0) { tmpp = -P[i]; chmin(&tmpp, -P[i] + Q[i] - P[j]); chmax(&ans, tmpp); } else if (D % 2 == 0) { tmpp = tmp * (D / 2) - Q[j]; chmin(&tmpp, tmp * (D / 2 - 1) - P[i]); chmax(&ans, tmpp); } else { tmpp = tmp * (D / 2) - P[i]; chmin(&tmpp, tmp * (D / 2) - Q[j]); chmax(&ans, tmpp); } } } printf("%d\n", ans); fflush(stdout); return 0; }