#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)(t.size()))); ++(i)) s << t[i] << " ";
  return s;
}
int dp[4096][4096], t[4096], d[4096];
int main() {
  int(n), (k);
  scanf("%d %d", &(n), &(k));
  if (k == n) {
    pisz(86400);
    return 0;
  }
  for (int(i) = 1; (i) <= (n); ++(i)) scanf("%d %d", t + i, d + i);
  int best = 0;
  for (int(j) = (0); (j) <= (k); ++j) dp[0][j] = 0;
  for (int(i) = (1); (i) <= (n); ++i)
    for (int(j) = (0); (j) <= (k); ++j) {
      int D = dp[i - 1][j];
      if (D + 1 < t[i]) {
        (best) = max((best), (t[i] - D - 1));
        ;
      }
      int cand = max(t[i], D + 1) + d[i] - 1;
      if (j > 0) {
        cand = min(cand, dp[i - 1][j - 1]);
      }
      dp[i][j] = cand;
    }
  (best) = max((best), (86400 - dp[n][k]));
  ;
  pisz(best);
}
