#include<iostream> #include<algorithm> #include<vector> #include<map> #include<cstdio> usingnamespacestd; constint N = 1e5 + 10; int dp[N], x[N], s[N], n, m;
intmain() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &s[i]); dp[0] = 0; for (int i = 1; i <= m; i++) dp[i] = i; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (x[j] >= i) dp[i] = min(dp[i], dp[max(x[j] - s[j] - 1, 0)]); else dp[i] = min(dp[i], dp[max(min(2 * x[j] - i - 1, x[j] - s[j] - 1), 0)] + max(0, i - (x[j] + s[j]))); } } printf("%d\n", dp[m]); }