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