#include <bits/stdc++.h>
using namespace std;
const int N = 37000;
const int M = 101;
int day[N];
pair<int, int> year[M];
int y;
void fill() {
  for (int i = 1; i < N; ++i) {
    day[i] = i % 7;
  }
}
bool leap(int a) { return (!(a % 4) && (a % 100)) || !(a % 400); }
void fnd() {
  int last = 1;
  for (int i = y; i < y + 100; ++i) {
    if (leap(i)) {
      year[i - y].first = last;
      year[i - y].second = last + 365;
      last += 366;
    } else {
      year[i - y].first = last;
      year[i - y].second = last + 364;
      last += 365;
    }
  }
}
bool same(int a) {
  a -= y;
  if (year[a].second - year[a].first != year[0].second - year[0].first) {
    return false;
  }
  for (int i = year[0].first, j = year[a].first;
       i <= year[0].second && j <= year[a].second; ++i, ++j) {
    if (day[i] != day[j]) {
      return false;
    }
  }
  return true;
}
void solve() {
  int ans = y + 1;
  while (!same(ans)) {
    ans++;
  }
  printf("%d", ans);
}
int main(int argc, char *argv[]) {
  fill();
  scanf("%d", &y);
  fnd();
  solve();
  return 0;
}
