#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
int mod = (int)1e9 + 7;
const int logN = 18;
const int inf = 1e9;
const int N = 1e6 + 5;
int n, m, x, y, z, t, a[N], b[N];
bool isleap(int x) {
  if (x % 400 == 0 || (x % 4 == 0 && x % 100)) return 1;
  return 0;
}
int main() {
  scanf("%d", &n);
  int p = 0, k = n;
  while (1) {
    p = (p + 365 + isleap(++n)) % 7;
    if (p == 0 && isleap(n) == isleap(k)) {
      cout << n << '\n';
      return 0;
    }
  }
  return 0;
}
