#include <bits/stdc++.h>
using namespace std;
bool isLeap(long long n) {
  if (!(n % 400) || !(n % 4) && (n % 100)) return true;
  return false;
}
int main() {
  long long n;
  cin >> n;
  int day[7] = {0, 1, 2, 3, 4, 5, 6};
  bool is = isLeap(n);
  for (int i = 0;;) {
    if (isLeap(n))
      i += 2;
    else
      i++;
    i %= 7;
    n++;
    if (i == 0 && isLeap(n) == is) break;
  }
  cout << n;
  return 0;
}
