#include <bits/stdc++.h>
using namespace std;
bool leap(int x) { return (x % 400 == 0 || (x % 4 == 0 && x % 100)); }
int main() {
  int n;
  cin >> n;
  int day = 0;
  for (int i = n + 1; 1; i++) {
    if (!leap(i))
      day = (day + 365) % 7;
    else
      day = (day + 366) % 7;
    if (day == 0 && leap(i) == leap(n)) return cout << i << endl, 0;
  }
  return 0;
}
