#include <bits/stdc++.h>
using namespace std;
const long long lINF = 1000000000000000000;
const int INF = 1000000000;
const long long mod = 1000000007;
const int N = 100001;
bool odd(int n) { return n % 4 == 0 && (n % 100 || n % 400 == 0); }
int main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int dop = 0, now = n;
  for (int(i) = (0); (i) < (100); (i)++) {
    dop++;
    dop += odd(now);
    now++;
    if (odd(now) == odd(n) && dop % 7 == 0) {
      cout << now;
      return 0;
    }
  }
  return 0;
}
