#include <bits/stdc++.h>
using namespace std;
bool leap(int year) {
  return (year % 400 == 0 || (year % 4 == 0 && (year % 100 != 0)));
}
int main() {
  int y;
  cin >> y;
  int day = 0, yi = y + 1;
  while (true) {
    int year = yi - 1;
    if (leap(year))
      day += 366;
    else
      day += 365;
    if (day % 7 == 0 && (leap(yi) == leap(y))) {
      cout << yi << endl;
      return 0;
    }
    yi++;
  }
  return 0;
}
