#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
const int SIZE = 1e6 + 5;
const int INF = 1e9 + 10;
bool is_leap(int n) { return n % 400 == 0 or (n % 4 == 0 and n % 100 != 0); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool isLeap = is_leap(n);
  long long days = 0;
  int ans = 0;
  for (int i = n + 1; i <= N; i++) {
    if (is_leap(i)) {
      days++;
    }
    days += 365;
    if (isLeap and days % 7 == 0) {
      if (is_leap(i)) {
        ans = i;
        break;
      }
    } else if (!isLeap and days % 7 == 0) {
      if (!is_leap(i)) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
