#include <bits/stdc++.h>
using namespace std;
bool isLeap(int yr) {
  if (yr % 4 == 0) {
    if (yr % 100 == 0) {
      if (yr % 400 == 0) {
        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  }
  return false;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int year;
  cin >> year;
  int tyear = year;
  int day = 0;
  int oday = 0;
  bool isit = isLeap(year);
  while (true) {
    tyear++;
    if (isLeap(tyear)) {
      oday = (oday + 2) % 7;
    } else {
      oday = (oday + 1) % 7;
    }
    if (oday == day && isit == isLeap(tyear)) {
      break;
    }
  }
  cout << tyear;
  return 0;
}
