#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265358979323846;
const int MAXN = 1e5 + 3;
long long n, a, b, p, q;
bool isLeap(int a) {
  if (a % 400 == 0) return true;
  if (a % 4 == 0 && a % 100) return true;
  return false;
}
void solve() {
  int y;
  cin >> y;
  int cnt = 0;
  bool f = 0;
  if (isLeap(y)) f = 1;
  y++;
  bool isl = 0;
  while (1) {
    cnt += 365;
    isl = isLeap(y);
    if (isl) cnt++;
    if (cnt % 7 == 0 && isl == f) break;
    y++;
  }
  cout << y;
}
int main() {
  solve();
  return 0;
}
