#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e3 + 4;
bool is_leap(int y) {
  if (y % 400 == 0) return 1;
  if (y % 100 != 0 and y % 4 == 0) return 1;
  return 0;
}
int main() {
  int y;
  scanf("%d", &y);
  if (is_leap(y)) {
    y++;
    int cur = 2;
    while (1) {
      if (cur % 7 == 0 and is_leap(y)) break;
      if (is_leap(y))
        cur += 2;
      else
        cur++;
      y++;
    }
    cout << y;
  } else {
    y++;
    int cur = 1;
    while (1) {
      if (cur % 7 == 0 and !is_leap(y)) break;
      if (is_leap(y))
        cur += 2;
      else
        cur++;
      y++;
    }
    cout << y;
  }
  return 0;
}
