#include <bits/stdc++.h>
using namespace std;
int glob = 1000;
int leap(int x) { return (x / 4) - (x / 100) + (x / 400); }
pair<int, int> get(int x) {
  int aux = 365 * (x - glob) + leap(x - 1) + 2;
  aux %= 7;
  bool isleap = x % 400 == 0 || (x % 4 == 0 && x % 100 != 0);
  return {aux, isleap};
}
int main() {
  int y;
  cin >> y;
  pair<int, int> ch = get(y);
  for (int i = 1; i <= 10000; i++) {
    if (get(y + i) == ch) {
      cout << y + i << endl;
      return 0;
    }
  }
  return 0;
}
