#include <bits/stdc++.h>
using namespace std;
bool leap(int x) { return ((x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0)); }
int main() {
  int n;
  cin >> n;
  int ans = n;
  int x = 0;
  while ((x != 0) || (leap(ans) != leap(n)) || (ans == n)) {
    x = (x + 365 + leap(ans)) % 7;
    ans++;
  }
  cout << ans << endl;
}
