#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void inp(T &any) {
  cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a, U &...b) {
  cin >> a;
  inp(b...);
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a) in >> x;
  return in;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int y;
    cin >> y;
    int d = 0;
    bool check = (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
    while (true) {
      d++;
      if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) d++;
      y++;
      d %= 7;
      if (d == 0 && check == (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)))
        break;
    }
    cout << y << "\n";
  }
}
