#include <bits/stdc++.h>
inline bool is_leap(int year) {
  if (year % 4) {
    return false;
  } else if (year % 100) {
    return true;
  } else if (year % 400) {
    return false;
  }
  return true;
}
int main() {
  int Year;
  int current = 2016;
  scanf("%d", &Year);
  current = Year;
  unsigned int days = 0;
  bool leap = is_leap(Year);
  while (true) {
    ++current;
    if (is_leap(current)) {
      days += 366;
    } else {
      days += 365;
    }
    if ((days % 7) == 0 && (is_leap(current) == leap)) {
      break;
    }
  }
  printf("%d", current);
  return 0;
}
