#include <bits/stdc++.h>
using namespace std;
bool leap(int n) {
  if (n % 4 == 0) {
    return (n % 400 == 0) || (n % 100 > 0);
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  bool is_leap = leap(n);
  for (int d = 0; d == 0 || (d % 7 != 0 || is_leap != leap(n)); ++n) {
    if (leap(n)) {
      d += 366;
    } else {
      d += 365;
    }
  }
  cout << n << endl;
  return 0;
}
