#include <bits/stdc++.h>
using namespace std;
bool isLeap(long long int in) {
  return (in % 400 == 0 or (in % 4 == 0 and in % 100 != 0));
}
int main() {
  ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  bool wasLeap = isLeap(n);
  long long int increment = 0ll;
  while (true) {
    increment += 1 + isLeap(n);
    n++;
    if (increment % 7 == 0 and isLeap(n) == wasLeap) break;
  }
  cout << n;
  return 0;
}
