#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4400;
int dp[MAXN][MAXN];
struct Node {
  int t, d;
  bool operator<(const Node &b) const { return t < b.t; }
} p[MAXN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].t, &p[i].d);
  sort(p + 1, p + n + 1);
  p[n + 1].t = 86401;
  dp[1][1] = 0;
  dp[1][0] = p[1].t - 1 + p[1].d;
  if (m == n) {
    printf("86400");
    return 0;
  }
  for (int i = 2; i <= n; ++i) {
    dp[i][0] = max(dp[i - 1][0], p[i].t - 1) + p[i].d;
    for (int j = 1; j <= m && j <= i; ++j) {
      int t = p[i].t - 1;
      if (i - 1 >= j) t = max(t, dp[i - 1][j]);
      dp[i][j] = min(dp[i - 1][j - 1], t + p[i].d);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      int t = min(n + 1, m - j + i + 1);
      ans = max(ans, p[t].t - 1 - dp[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
