#include <bits/stdc++.h>
using namespace std;
int gcdEx(int a, int b, int *x, int *y) {
  if (!a) {
    *x = 0;
    *y = 1;
    return b;
  }
  int x1, y1, gcd = gcdEx(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
int modI(int b, int m) {
  int x, y;
  gcdEx(b, m, &x, &y);
  return (x % m + m) % m;
}
long long modP(long long x, long long y) {
  long long r = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) {
      r = (r * x) % 1000000007;
    }
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return r;
}
int VERBOSE = 0;
void code() {
  int x = 0, y;
  cin >> y;
  int yl = (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)), il;
  for (int i = y + 1; i <= (y + 100); ++i) {
    x++;
    il = (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0));
    if (il) x++;
    x %= 7;
    if (x == 0 && yl == il) {
      cout << i;
      return;
    }
  }
}
int main(int argc, char *argv[]) {
  if (argc == 2 && argv[1][1] == 'v') {
    VERBOSE = 1;
  }
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  code();
  return 0;
}
