#include <bits/stdc++.h>
using namespace std;
int check(int y) {
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
    return 1;
  else
    return 0;
}
int main() {
  int y;
  int flag, d = 0;
  cin >> y;
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
    flag = 1;
  else
    flag = 0;
  do {
    d++;
    if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) d++;
    y++;
    d = d % 7;
  } while (d != 0 || (check(y) != flag));
  cout << y;
}
