#include <bits/stdc++.h>
using namespace std;
bool leap(int y) {
  if (y % 400 == 0) return true;
  if (y % 4 == 0 && y % 100 != 0) return true;
  return false;
}
bool similar(int y1, int y2) {
  if (leap(y1) && leap(y2)) return true;
  if (leap(y1) || leap(y2)) return false;
  return true;
}
int main() {
  int y;
  scanf("%d", &y);
  int Y = y;
  long long d = 0;
  long long t = 0;
  while (true) {
    d += (leap(y)) ? 366 : 365;
    y++;
    if (d % 7 == 0 && similar(Y, y)) {
      printf("%d\n", y);
      return 0;
    }
  }
  return 0;
}
