#include <bits/stdc++.h>
using namespace std;
int judge(int y) {
  if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
    return 2;
  else
    return 1;
}
int main() {
  long long int y, x = 0;
  cin >> y;
  int temp = y;
  while (1) {
    temp++;
    x += judge(temp);
    if (x % 7 == 0 && judge(temp) == judge(y)) {
      cout << temp;
      return 0;
    }
  }
  return 0;
}
