#include <bits/stdc++.h>
using namespace std;
bool isLeap(int y) {
  return (y % 400 == 0) ? true : ((y % 4 == 0 && y % 100) ? true : false);
}
int main() {
  int y;
  cin >> y;
  int x = y;
  int t = rand() % 7;
  int d = t;
  do {
    d += (isLeap(++y)) ? 2 : 1;
    d %= 7;
  } while (d != t || isLeap(x) != isLeap(y));
  cout << y;
  return 0;
}
