#include <bits/stdc++.h>
using namespace std;
bool leap_year(int n) { return n % 400 == 0 or (n % 4 == 0 and n % 100); }
int main() {
  int y, cnt, temp;
  cin >> y;
  temp = y;
  temp++;
  cnt = 0;
  while (true) {
    cnt++;
    if (leap_year(temp)) cnt++;
    if (cnt % 7 == 0 and leap_year(temp) == leap_year(y)) break;
    temp++;
  }
  cout << temp;
  return 0;
}
