#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
bool leap(int y) { return (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0); }
int ans[110000];
int main() {
  ans[2000] = 6;
  for (int i = 2001; i < 110000; i++) {
    ans[i] = ans[i - 1] + 1;
    if (leap(i - 1)) ans[i]++;
    ans[i] = (ans[i] - 1) % 7 + 1;
  }
  for (int i = 1999; i >= 1000; i--) {
    ans[i] = ans[i + 1] - 1;
    if (leap(i)) ans[i]--;
    if (ans[i] <= 0) ans[i] += 7;
  }
  int x;
  scanf("%d", &x);
  for (int i = x + 1; i < 110000; i++) {
    if (ans[i] == ans[x] && leap(i) == leap(x)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
