#include <bits/stdc++.h>
using namespace std;
bool leap(int x) { return (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0)); }
int main() {
  int y;
  cin >> y;
  int c = 365 + leap(y), in = y + 1;
  while (true) {
    c %= 7;
    if (c == 0 && leap(y) == leap(in)) {
      cout << in << endl;
      return 0;
    }
    c += 365 + leap(in);
    in++;
  }
}
