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