#include <bits/stdc++.h>
using namespace std;
bool leap(int y) {
  if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
    return true;
  else
    return false;
}
int main() {
  int n, f;
  cin >> n;
  int ct = 1;
  f = leap(n);
  n++;
  if (leap(n)) ct++;
  while (ct % 7 != 0 || leap(n) != f) {
    n++;
    ct++;
    if (leap(n)) ct++;
  }
  cout << n << "\n";
  return 0;
}
