#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 17;
const int MX = (int)1e6 + 17;
const int MOD = (int)1e9 + 7;
const long long oo = LLONG_MAX;
const int INF = INT_MAX;
const long double Pi = 3.14159265358979323846264338327950288419716939937510;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};
inline long long IN() {
  long long x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void OUT(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    OUT(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
void IOI2017() {
  freopen(
      "partition"
      ".in",
      "r", stdin);
  freopen(
      "partition"
      ".out",
      "w", stdout);
}
int n, cur = 4;
struct Week {
  int w[10];
};
Week a[2 * N];
int Year(int x) {
  if (x % 400 == 0 || x % 4 == 0 && x % 100) return 366;
  return 365;
}
bool check(Week a, Week b) {
  for (int i = 1; i <= 7; i++) {
    if (a.w[i] != b.w[i]) return 0;
  }
  return 1;
}
int main() {
  for (int i = 1000; i <= N * 2; i++) {
    for (int j = 1; j <= Year(i); j++) {
      a[i].w[cur]++;
      cur++;
      if (cur == 8) cur = 1;
    }
  }
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int j = n + 1;; j++) {
    if (check(a[n], a[j])) {
      cout << j;
      return 0;
    }
  }
  return 0;
}
