#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const long long MOD = 1000000007;
bool check(int y) {
  if (y % 400 == 0) return true;
  if (y % 4 == 0 && y % 100) return true;
  return false;
}
int main(void) {
  int y;
  scanf("%d", &y);
  bool isLeap = check(y);
  int k = 0;
  do {
    k += (check(y++) ? 366 : 365);
    k %= 7;
  } while (k || check(y) != isLeap);
  cout << y << endl;
  return 0;
}
