#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i = 0, j, k, l, n, m;
  cin >> n;
  if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
    j = 1;
  else
    j = 0;
  while (1) {
    if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
      i = (i + 2) % 7;
    else
      i = (i + 1) % 7;
    if (i == 0) {
      if (j == 1) {
        if ((n + 1) % 400 == 0 || ((n + 1) % 4 == 0 && (n + 1) % 100 != 0))
          break;
      } else if (j == 0) {
        if ((n + 1) % 400 == 0 || ((n + 1) % 4 == 0 && (n + 1) % 100 != 0))
          ;
        else
          break;
      }
    }
    n++;
  }
  cout << n + 1;
  return 0;
}
