#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int x = n + 1, y = 0, f1 = 0, f;
  if (n % 400 == 0)
    f1 = 1;
  else if (n % 100 != 0 && n % 4 == 0)
    f1 = 1;
  do {
    f = 0;
    if (x % 400 == 0)
      f = 1;
    else if (x % 100 != 0 && x % 4 == 0)
      f = 1;
    x++;
    y++;
    if (f) y++;
    y = y % 7;
  } while (y != 0 || (f1 != f));
  printf("%d\n", x - 1);
  return 0;
}
