#include <bits/stdc++.h>
const int maxn = 1e2 + 10;
const int dis[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p;
    p = p * p;
    q >>= 1;
  }
  return f;
}
int work(int p) {
  if (p % 400 == 0 || (p % 4 == 0 && p % 100 != 0))
    return 1;
  else
    return 0;
}
int main() {
  int i, j, m, n, k, t;
  scanf("%d", &n);
  int f = 0;
  if (work(n)) f = 1;
  int cnt = 0;
  while (1) {
    n++;
    cnt++;
    if (work(n)) cnt++;
    if (cnt % 7 == 0 && f == work(n)) break;
  }
  printf("%d\n", n);
  return 0;
}
