import std; void main() { int N, D; readf("%d %d\n", N, D); auto P = new long[](N), Q = new long[](N); foreach (i; 0 .. N) { readf("%d %d\n", P[i], Q[i]); } long res = long.min; foreach (i; 0 .. N) { foreach (j; 0 .. N) { if (i == j) { continue; } long diff = Q[i] + Q[j] - P[i] - P[j]; if (diff >= 0) { long tmp = min(-P[i], -P[i]-P[j]+Q[i]); res = max(res, tmp); } else { long tmp = diff * ((D - 1) / 2); tmp -= P[i]; if (D % 2 == 0) { tmp = min(tmp, tmp-P[j]+Q[i]); } res = max(res, tmp); } } } res.writeln; }