#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main(){ ll N, K, M, A, B, ans=0; cin >> N >> K; vector dp(N+1, -1e18); dp[0] = 0; for (int i=1; i<=N; i++){ cin >> A >> M; dp[i] = max(dp[0]-A, dp[i]); for (int j=0; j> B; dp[i] = max(dp[i], dp[B]); dp[0] = max(dp[0], dp[i]+A); } } cout << dp[0] << endl; return 0; }