#include <bits/stdc++.h>
using namespace std;
bool leap(int y) { return (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long y;
  cin >> y;
  bool is_leap = leap(y);
  int d = 0;
  do {
    d++;
    if (leap(y)) d++;
    y++;
    d %= 7;
  } while (d || leap(y) != is_leap);
  cout << y << endl;
  return 0;
}
