#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int year;
  int fisrt;
  cin >> year;
  fisrt = year;
  int day = 0;
  while (true) {
    year++;
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
      day = (day + 2) % 7;
    } else {
      day = (day + 1) % 7;
    }
    if (day == 0) {
      if (fisrt % 400 == 0 || (fisrt % 4 == 0 && fisrt % 100 != 0)) {
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
          cout << year << endl;
          break;
        }
      } else {
        if (!(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) {
          cout << year << endl;
          break;
        }
      }
    }
  }
  return 0;
}
