#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using pl = pair<long long, long long>;
using vll = vector<long long>;
using mll = map<long long, long long>;
using vpl = vector<pl>;
long long mod = 1000000007;
long long modu(long long a, long long b) {
  long long c = a % b;
  return (c < 0) ? c + b : c;
}
long long ipow(long long a, long long b) {
  long long ans = 1;
  while (b--) {
    ans = ans * a;
  }
  return ans;
}
long long getmx(long long i, long long j, long long i1, long long j1,
                long long i2, long long j2) {
  long long ans = 0;
  ans += abs(i - i1) + abs(j - j1);
  ans += abs(i1 - i2) + abs(j1 - j2);
  ans += abs(i - i2) + abs(j - j2);
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool isleap(long long n) {
  if (n % 400 == 0) return true;
  if (n % 4 == 0 && n % 100 != 0) return true;
  return false;
}
void solve() {
  long long n, dif = 0;
  cin >> n;
  for (long long i = n + 1;; i++) {
    if (isleap(i)) {
      dif += 2;
    } else {
      dif++;
    }
    if (dif % 7 == 0 && (isleap(i) == isleap(n))) {
      cout << i << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
