#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const double Pi = acos(-1.0);
const int Max = 40;
int Leap(int year) {
  if (!(year % 4) && year % 100 || !(year % 400)) return 366;
  return 365;
}
int main() {
  int year, day;
  while (~scanf("%d", &year)) {
    day = 0;
    int mark = 0, yes = Leap(year);
    while (day || !mark || yes != Leap(year)) {
      day = (day + Leap(year)) % 7;
      year++;
      mark = 1;
    }
    printf("%d\n", year);
  }
  return 0;
}
