#include <bits/stdc++.h>
using namespace std;
int sum;
int main() {
  int n;
  cin >> n;
  int z, d;
  if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
    z = 366;
  else
    z = 365;
  int nxt = n + 1;
  if (nxt % 400 == 0 || (nxt % 4 == 0 && nxt % 100 != 0))
    d = 366;
  else
    d = 365;
  sum = d;
  while (sum % 7 != 0 || d != z) {
    nxt++;
    if (nxt % 400 == 0 || (nxt % 4 == 0 && nxt % 100 != 0))
      d = 366;
    else
      d = 365;
    sum += d;
  }
  cout << nxt << endl;
}
