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