#include <bits/stdc++.h>
using namespace std;
int days(int y) {
  if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) return 366;
  return 365;
}
int main() {
  int y;
  cin >> y;
  int x = 0;
  int dini = days(y);
  do {
    x = (x + days(y)) % 7;
    y++;
  } while (x != 0 || days(y) != dini);
  cout << y << endl;
}
