#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5 + 10;
const long long mod = 998244353;
bool ck(int y) {
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
    return true;
  }
  return false;
}
int main() {
  int y;
  cin >> y;
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
    int cnt = 0;
    while (1) {
      y++;
      if (ck(y))
        cnt += 2;
      else
        cnt++;
      if (cnt != 0 && cnt % 7 == 0 && ck(y)) break;
    }
    cout << y << endl;
  } else {
    int cnt = 0;
    while (1) {
      y++;
      if (ck(y))
        cnt += 2;
      else
        cnt++;
      if (cnt != 0 && cnt % 7 == 0 && !ck(y)) break;
    }
    cout << y << endl;
  }
}
