#include <bits/stdc++.h>
using namespace std;
bool isLeapYear(long long y) {
  if (y % 4 == 0) {
    if (y % 100 == 0 and y % 400 == 0)
      return true;
    else if (y % 100 == 0 and y % 400 != 0)
      return false;
    else
      return true;
  } else
    return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  int precision = numeric_limits<double>::digits10;
  ;
  long long y;
  cin >> y;
  long long ans = y, rem;
  if (isLeapYear(ans))
    rem = 2;
  else
    rem = 1;
  ans++;
  while (true) {
    if (rem % 7 == 0) {
      if ((isLeapYear(y) and isLeapYear(ans)) or
          (!isLeapYear(y) and !isLeapYear(ans)))
        break;
    }
    if (isLeapYear(ans))
      rem += 2;
    else
      rem += 1;
    ans++;
  }
  cout << ans << endl;
}
