#include <bits/stdc++.h>
using namespace std;
bool vis(int n) {
  if (n % 400 == 0) return 1;
  if (n % 100 == 0) return 0;
  if (n % 4 == 0) return 1;
  return 0;
}
int main() {
  int n;
  cin >> n;
  int ans = 1;
  bool x = vis(n);
  if (x) ans++;
  n++;
  while (ans % 7 != 0 || vis(n) != x) {
    ans++;
    if (vis(n)) ans++;
    n++;
  }
  cout << n;
  return 0;
}
