#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
#pragma GCC optimize("O3")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007LL;
const long long INF2 = 1000000007LL * 1000000007LL;
const long double EPS = 1e-9;
const int SIZE = 200010;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
int len_year(int y) {
  if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) return 366;
  return 365;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int year, sum = 0, start;
  cin >> year;
  start = year;
  sum = len_year(year) % 7;
  while (sum || len_year(year + 1) != len_year(start)) {
    ++year;
    sum = (sum + len_year(year)) % 7;
  }
  cout << year + 1;
  return 0;
}
