#include <bits/stdc++.h>
int days(int y) {
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
    return 366;
  } else {
    return 365;
  }
}
int main() {
  int year, i, d, di, dii;
  unsigned long long int count = 0;
  scanf("%d", &year);
  d = days(year);
  di = d;
  for (i = year;; i++) {
    dii = days(i + 1);
    count += di;
    if (count % 7 == 0 && d == dii) {
      printf("%d\n", i + 1);
      return 0;
    }
    di = dii;
  }
  return 0;
}
