#include <bits/stdc++.h>
using namespace std;
int dp[100005][10];
bool bin(int y) { return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); }
int main() {
  int n;
  cin >> n;
  int sum = 0;
  if (bin(n)) {
    sum == 2;
  } else {
    sum == 1;
  }
  int s = n;
  while (1) {
    n++;
    if (bin(n)) {
      sum += 2;
    } else {
      sum += 1;
    }
    if (sum % 7 == 0 && bin(n) == bin(s)) {
      break;
    }
  }
  cout << n;
}
