#include <bits/stdc++.h>
using namespace std;
template <typename Iter>
ostream& _out(ostream& s, Iter a, Iter b) {
  for (auto it = a; it != b; it++) s << (it == a ? "" : " ") << *it;
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, pair<A, B>& p) {
  return s << "(" << p.first << " , " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
  return _out(s, v.begin(), v.end());
}
inline long long rit() {
  int key = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') key = -1;
    c = getchar();
  }
  long long x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * key;
}
int __ = 1;
void init() {}
void read() {}
void solve() {}
int main() {
  int y = rit();
  if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
    int now = 2;
    for (y = y + 1;; y++) {
      if (now == 0 && ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))) {
        cout << y << endl;
        break;
      }
      now = (now + 1) % 7;
      if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) now = (now + 1) % 7;
    }
  } else {
    int now = 1;
    for (y = y + 1;; y++) {
      if (now == 0 && !(y % 4 == 0 && y % 100 != 0) && !(y % 400 == 0)) {
        cout << y << endl;
        break;
      }
      now = (now + 1) % 7;
      if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) now = (now + 1) % 7;
    }
  }
  return 0;
}
