#include <bits/stdc++.h>
using namespace std;
bool isLeap(int x) {
  if (x % 400 == 0) {
    return 1;
  }
  if (x % 100 == 0) {
    return 0;
  }
  if (x % 4 == 0) {
    return 1;
  }
  return 0;
}
int main() {
  int yy;
  cin >> yy;
  int days = 0;
  int ans = yy;
  while (1) {
    if (isLeap(ans)) {
      days += 366;
    } else {
      days += 365;
    }
    ans++;
    if (days % 7 == 0 && isLeap(ans) == isLeap(yy)) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
