#include <bits/stdc++.h>
using namespace std;
int n;
int dia;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  dia = 0;
  bool ok = false;
  if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
    ok = true;
  }
  for (int i = 1000; i < n; i++) {
    if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
      dia += 2;
    } else {
      dia++;
    }
    dia = dia % 7;
  }
  int ans = 0;
  int x = dia;
  for (int i = n + 1; i <= int(1e7); i++) {
    bool ok2 = false;
    if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
      x += 2;
      ok2 = true;
    } else {
      x++;
    }
    x = x % 7;
    if (x == dia && ok == ok2) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
