#include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265358979;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
bool isleap(long long x) {
  return ((x % 4 == 0) && (x % 100)) || (x % 400 == 0);
}
void solve() {
  long long n;
  cin >> n;
  bool ok = isleap(n);
  long long day = 0;
  while (true) {
    if (isleap(n)) {
      day += 366;
    } else
      day += 365;
    day = day % 7;
    n++;
    if (!day && !(ok ^ isleap(n))) {
      cout << n;
      return;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
