#include <bits/stdc++.h>
int is_leap(int i) {
  if ((i % 4 == 0 && i % 100 != 0) || ((i % 100 == 0 && i % 400 == 0)))
    return 1;
  else
    return 0;
}
int main(void) {
  long long int i, j, n, m, t, count = 0;
  scanf("%lld", &n);
  int p = is_leap(n);
  for (i = n;;) {
    if (is_leap(i))
      count += 2;
    else
      count += 1;
    i++;
    if (count % 7 == 0 && is_leap(i) == p) break;
  }
  printf("%lld", i);
  return 0;
}
