#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X abs(const X& a) {
  return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
  return a * a;
}
bool isleap(int second) {
  return second % 400 == 0 || (second % 4 == 0 && second % 100 != 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int second;
  cin >> second;
  bool leap = isleap(second);
  int ny = second;
  int c = 0;
  while (true) {
    if (c % 7 == 0 && isleap(ny) == leap && second != ny)
      break;
    else if (isleap(ny)) {
      ny++;
      c += 2;
    } else {
      ny++;
      c++;
    }
  }
  cout << ny;
}
