#include <bits/stdc++.h>
using namespace std;
int is_leap(int x) {
  if (x % 400 == 0) return 1;
  if (x % 4 == 0 && x % 100 != 0) return 1;
  return 0;
}
int main() {
  int y;
  cin >> y;
  int lf = 0;
  if (is_leap(y)) lf = 1;
  int ad = 0;
  while (1) {
    if (is_leap(y))
      ad += 366;
    else
      ad += 365;
    if (ad % 7 == 0) {
      if (lf && is_leap(y + 1)) {
        cout << y + 1 << endl;
        return 0;
      }
      if (!lf && !is_leap(y + 1)) {
        cout << y + 1 << endl;
        return 0;
      }
    }
    y++;
  }
}
