#include <bits/stdc++.h>
using namespace std;
bool pdleapyear(int year) {
  if (year % 4 == 0 && year % 100 != 0) {
    return true;
  } else if (year % 400 == 0) {
    return true;
  } else
    return false;
}
int getDay(int year) {
  if (pdleapyear(year)) {
    return 366;
  } else
    return 365;
}
int main() {
  int year;
  cin >> year;
  int leap = 0;
  int thisDay = getDay(year);
  while (true) {
    year++;
    int nowDay = getDay(year);
    leap += nowDay % 7;
    if (leap % 7 == 0 && thisDay == nowDay) {
      break;
    }
  }
  cout << year << endl;
  return 0;
}
