#include <bits/stdc++.h>
const long double pie = 3.1415926535;
using namespace std;
long long fpow(long long n, long long p) {
  long long m = 1;
  while (p) {
    if (p % 2) m *= n;
    p >>= 1;
    n *= n;
  }
  return m;
}
long long mfpow(long long n, long long p, long long M) {
  long long m = 1;
  n %= M;
  while (p) {
    if (p % 2) m = (m * n) % M;
    n = (n * n) % M;
    p >>= 1;
  }
  return m % M;
}
const vector<long long> days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool br1, br2, br;
char ch, ch1, ch2;
long long n, k, x, y, z, mini, maxi, l, ind, ini, sum, t, len, r, w, imini, m;
string s, s1, s2;
bool isLeap(long long x) {
  if (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0)) return true;
  return false;
}
void solve() {
  cin >> x;
  if (isLeap(x)) br = 1;
  y = 0;
  while (true) {
    if (isLeap(++x))
      y = 366;
    else
      y = 365;
    z = (z + y) % 7;
    if (z == 0 && br == isLeap(x)) {
      cout << x << endl;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
