#include <bits/stdc++.h>
using namespace std;
int f(int y) {
  return y % 400 == 0 ? 2 : y % 100 == 0 ? 1 : y % 4 == 0 ? 2 : 1;
}
int main() {
  int n, r = 0, t;
  scanf("%d", &n);
  t = f(n);
  while (r % 7 != 0 || r == 0 || t != f(n)) {
    r += f(n);
    n++;
  }
  printf("%d\n", n);
  return 0;
}
