#include <bits/stdc++.h>
using namespace std;
bool ifl(long long year) {
  if (year % 100 != 0) {
    if (year % 4 == 0)
      return true;
    else
      return false;
  } else if (year % 400 == 0)
    return true;
  else
    return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long rem = 0;
  if (ifl(n)) {
    while (1) {
      n++;
      if (ifl(n))
        rem += 2;
      else
        rem += 1;
      rem %= 7;
      if (rem == 0 && ifl(n)) {
        cout << n;
        return 0;
      }
    }
  } else
    while (1) {
      n++;
      if (ifl(n))
        rem += 2;
      else
        rem += 1;
      rem %= 7;
      if (rem == 0 && !ifl(n)) {
        cout << n;
        return 0;
      }
    }
  return 0;
}
