#include <bits/stdc++.h>
using namespace std;
int n, l, rst;
int isl(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100); }
int main() {
  cin >> n;
  l = isl(n);
  rst = l ? 2 : 1;
  while (rst || l != isl(n + 1)) {
    ++n;
    rst += isl(n) ? 2 : 1;
    rst %= 7;
  }
  cout << n + 1;
}
