#include <bits/stdc++.h>
int n, k;
int calt[4010], cald[4010];
int dp[4010];
int bs(int le, int ri, int tar) {
  if (le == ri) return le;
  int mi = (le + ri + 1 >> 1);
  int val = dp[mi];
  if (val >= tar) return bs(le, mi - 1, tar);
  if (val < tar) return bs(mi, ri, tar);
}
int main(void) {
  for (int i = 1; i < 4010; ++i) dp[i] = 999999999;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &calt[i], &cald[i]);
  k = n - k + 1;
  n += 1;
  calt[0] = 0, cald[0] = 1;
  calt[n] = 86401, cald[n] = 1;
  for (int i = 1; i < n - k + 1; ++i) {
    for (int j = i; j > 0; --j) {
      dp[j] = std::min(dp[j], std::max(dp[j - 1] + 1, calt[i]) + cald[i] - 1);
    }
  }
  int ans = calt[n - k + 1] - 1;
  for (int i = n - (k - 1) + 1; i <= n; ++i) {
    for (int j = i - 1; j > 0; --j) {
      dp[j] = std::min(dp[j],
                       std::max(dp[j - 1] + 1, calt[i - 1]) + cald[i - 1] - 1);
    }
    ans = std::max(ans, calt[i] - dp[i - n + k - 1] - 1);
  }
  printf("%d\n", ans);
  return 0;
}
