#include <bits/stdc++.h>
using namespace std;
bool cmp(vector<long long int> a, vector<long long int> b) {
  return a[0] > b[0];
}
bool sortfirst(pair<long long int, char> a, pair<long long int, char> b) {
  return a.first > b.first;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
bool isPowerOfTwo(int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
double sumOfGP(double a, double r, int n) {
  double sum = 0;
  for (int i = 0; i < n; i++) {
    sum = sum + a;
    a = a * r;
  }
  return sum;
}
bool check(string s) {
  stack<char> st;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == '(')
      st.push('(');
    else {
      if (st.empty()) {
        return false;
      } else
        st.pop();
    }
  }
  if (st.empty())
    return true;
  else
    return false;
}
long long int mod = 1000000007;
bool iszero(string a) {
  for (long long int i = 0; i < a.length(); i++) {
    if (a[i] == '1') return false;
  }
  return true;
}
long long int fac(long long int n) {
  if (n <= 0) return 1;
  return (n * fac(n - 1)) % mod;
}
bool subArrayExists(long long int arr[], int n) {
  unordered_set<long long int> sumSet;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
    if (sum == 0 || sumSet.find(sum) != sumSet.end()) return true;
    sumSet.insert(sum);
  }
  return false;
}
int extraDays(int y) {
  if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) return 2;
  return 1;
}
int nextYear(int y) {
  int days = extraDays(y);
  int x = y + 1;
  for (int sum = 0;; x++) {
    sum = (sum + extraDays(x)) % 7;
    if (sum == 0 && (extraDays(x) == days)) return x;
  }
  return x;
}
void solve() {
  int y;
  cin >> y;
  cout << nextYear(y);
}
int main() {
  solve();
  return 0;
}
