#include <bits/stdc++.h>
using namespace std;
bool leap(int n) {
  if (n % 100 == 0) {
    if (n % 400 == 0) return true;
    return false;
  }
  if (n % 4) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int y = n;
  int cnt = 0;
  while (1) {
    if (leap(y))
      cnt += 366;
    else
      cnt += 365;
    cnt %= 7;
    y++;
    if (!cnt) {
      if (leap(y) == leap(n)) {
        cout << y;
        return 0;
      }
    }
  }
  return 0;
}
