#include <bits/stdc++.h>
using namespace std;
int check(int n) {
  if (n % 400 == 0) return 1;
  if (n % 100 != 0 && n % 4 == 0) return 1;
  return 0;
}
int main() {
  int n, cnt = 0, flag = 0;
  cin >> n;
  if (check(n)) flag = 1;
  while (1) {
    if (check(n))
      cnt += 366;
    else
      cnt += 365;
    n++;
    if (cnt % 7 == 0) {
      if (flag == 0)
        if (!check(n)) {
          cout << n;
          return 0;
        }
      if (flag == 1)
        if (check(n)) {
          cout << n;
          return 0;
        }
    }
  }
  return 0;
}
