#include <bits/stdc++.h>
using namespace std;
bool check(int year) {
  if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return true;
  return false;
}
void solve() {
  int x;
  scanf("%d", &x);
  int day = 0;
  bool flag = check(x);
  do {
    if (check(x))
      day += 366;
    else
      day += 365;
    day %= 7;
    x++;
  } while (day != 0 || check(x) != flag);
  printf("%d\n", x);
}
int main() {
  solve();
  return 0;
}
