#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e+9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long MAXN = 2e+3 + 500;
const long long MAXN1 = 1e+6 + 8;
string P[100];
bool isLeap(long long y) {
  if (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0))
    return true;
  else
    return false;
}
int main() {
  long long y;
  cin >> y;
  long long res = 0;
  long long match = 0;
  int i;
  for (i = 1000; i < y; i++) {
    if (isLeap(i)) {
      res = (res + 2) % 7;
      match = (match + 2) % 7;
    } else {
      res = (res + 1) % 7;
      match = (match + 1) % 7;
    }
  }
  while (1) {
    if (isLeap(i)) {
      res = (res + 2) % 7;
    } else {
      res = (res + 1) % 7;
    }
    if (res == match) {
      if (isLeap(i + 1) == isLeap(y)) {
        cout << i + 1 << endl;
        break;
      }
    }
    i++;
  }
}
