#include <bits/stdc++.h>
int n, days, leap, flag;
void count(int tmp, int days) {
  if (tmp % 400 == 0 || (tmp % 4 == 0 && tmp % 100 != 0)) {
    days += 2;
    flag = 1;
  } else {
    days++;
    flag = 0;
  }
  if (days % 7 == 0) {
    if (flag == leap) {
      printf("%d\n", tmp);
      return;
    } else
      count(tmp + 1, days);
  } else
    count(tmp + 1, days);
}
int main() {
  scanf("%d", &n);
  days = 0;
  if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
    leap = 1;
  } else {
    leap = 0;
  }
  count(n + 1, 0);
}
