#include <bits/stdc++.h>
using namespace std;
int n, x;
long long h;
int getday(int q) {
  int y;
  if (q % 4 == 0 && q % 100 != 0 || q % 400 == 0)
    y = 366;
  else
    y = 365;
  return y;
}
int main() {
  cin >> n;
  x = getday(n);
  for (int i = n + 1;; i++) {
    h += getday(i - 1);
    if (getday(i) == getday(n) && h % 7 == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
