#include <bits/stdc++.h>
using namespace std;
bool nhuan(long long &a) {
  if ((a % 400 == 0) || ((a % 4 == 0) && (a % 100 != 0))) {
    return true;
  }
  return false;
}
int main() {
  long long n;
  cin >> n;
  long long i = 2;
  long long m = n;
  bool t = true;
  while ((i != 2) || (m == n) || (t)) {
    m += 1;
    if (nhuan(m)) {
      i += 2;
    } else
      i += 1;
    if (i > 8) {
      i = (i - 8) + 1;
    }
    if (((nhuan(m)) && (nhuan(n))) ||
        ((nhuan(m) == false) && (nhuan(n) == false))) {
      t = false;
    } else
      t = true;
  }
  cout << m;
  return 0;
}
