#include <bits/stdc++.h>
using namespace std;
bool leap(long long int y) {
  if (y % 4 != 0) {
    return false;
  } else {
    if (y % 100 != 0) {
      return true;
    } else {
      if (y % 400 == 0) {
        return true;
      } else {
        return false;
      }
    }
  }
}
int main() {
  long long int n;
  cin >> n;
  int cnt = 0;
  if (leap(n)) {
    for (long long int j = n + 1;; j++) {
      if (leap(j)) {
        cnt += 2;
      } else {
        cnt += 1;
      }
      if (cnt == 7 && leap(j)) {
        cout << j << endl;
        return 0;
      } else if (cnt >= 7) {
        cnt -= 7;
      }
    }
  } else {
    for (long long int j = n + 1;; j++) {
      if (leap(j)) {
        cnt += 2;
      } else {
        cnt += 1;
      }
      if (cnt == 7 && !leap(j)) {
        cout << j << endl;
        return 0;
      } else if (cnt >= 7) {
        cnt -= 7;
      }
    }
  }
}
