#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, d;
  friend bool operator<(const node &a, const node &b) { return a.t < b.t; }
} a[4010];
int f[2][4010];
int now, nxt;
int n, m;
int ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d%d", &a[i].t, &a[i].d);
  sort(a, a + n);
  memset(f, 0, sizeof(f));
  now = 0;
  ans = 0;
  for (int i = 0; i <= m; i++) f[0][i] = 1;
  for (int i = 0; i < n; i++) {
    nxt = (now ^ 1);
    for (int j = 0; j <= m; j++) {
      if (f[now][j] < a[i].t) ans = max(ans, a[i].t - f[now][j]);
      f[nxt][j] = max(a[i].t, f[now][j]) + a[i].d;
      if (j) f[nxt][j] = min(f[nxt][j], f[now][j - 1]);
      if (i == n - 1 && f[nxt][j] <= 86400) ans = max(ans, 86401 - f[nxt][j]);
    }
    now = nxt;
  }
  if (n <= m) ans = 86400;
  printf("%d\n", ans);
  return 0;
}
