#include <bits/stdc++.h>
using namespace std;
int isleap(long long int y) {
  if ((y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0)))
    return 1;
  else
    return 0;
}
int main() {
  long long int num, n, k, ans, f = 0;
  cin >> n;
  f = isleap(n);
  ans = n;
  num = 0;
  while (1) {
    if (isleap(ans))
      num = num + 366;
    else
      num = num + 365;
    if (num % 7 == 0) {
      if (f == 1) {
        if (isleap(ans + 1)) {
          cout << ans + 1;
          break;
        }
      } else {
        if (!isleap(ans + 1)) {
          cout << ans + 1;
          break;
        }
      }
    }
    ans++;
  }
  return 0;
}
