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