#include <bits/stdc++.h>
using namespace std;
bool isLeap(int y) { return ((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0)); }
int main() {
  int x, y, sum = 0;
  cin >> y;
  x = y;
  do {
    sum += isLeap(y++) + 1;
  } while (sum % 7 != 0 || isLeap(x) != isLeap(y));
  cout << y << endl;
  return 0;
}
