#include <bits/stdc++.h>
using namespace std;
int flag[13], change[13];
bool is_leap(int y) {
  if (y % 100 == 0)
    return y % 400 == 0;
  else
    return y % 4 == 0;
}
int main() {
  memset(flag, 0, sizeof(flag));
  memset(change, 0, sizeof(change));
  int y;
  cin >> y;
  while (1) {
    bool last = is_leap(y);
    y++;
    bool now = is_leap(y);
    if (last && (!now))
      for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1 + (i <= 2)) % 7;
    else if ((!last) && now)
      for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1 + (i >= 3)) % 7;
    else
      for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1) % 7;
    bool ok = true;
    for (int i = 1; i <= 12; i++)
      if (flag[i] != change[i]) {
        ok = false;
        break;
      }
    if (ok) break;
  }
  cout << y << endl;
  return 0;
}
