#include <bits/stdc++.h>
using namespace std;
int run(int n) {
  if (n % 4 == 0) {
    if (n % 100 == 0) {
      if (n % 400 == 0)
        return 366;
      else
        return 365;
    } else
      return 366;
  } else
    return 365;
}
int main() {
  int y;
  cin >> y;
  int ant = 0;
  for (int a = y;; a++) {
    ant = (ant + run(a)) % 7;
    if ((ant == 0) && run(y) == run(a + 1)) {
      cout << a + 1;
      break;
    }
  }
  return 0;
}
