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