#include <bits/stdc++.h>
const int LIM = 1e5;
using namespace std;
int f(int y) {
  int res = (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) ? 2 : 1;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x, s;
  cin >> n;
  for (x = f(n), s = 0;; n++) {
    s = (s + f(n)) % 7;
    if (s == 0 && f(n + 1) == x) break;
  }
  cout << n + 1 << '\n';
  return 0;
}
