#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
const int M = 1e9 + 7;
bool leap(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int y;
  cin >> y;
  int f = y;
  int cnt = 0;
  do {
    if (leap(y))
      cnt += 366 % 7;
    else
      cnt += 365 % 7;
    y++;
  } while ((cnt % 7) != 0 || leap(f) != leap(y));
  cout << y << endl;
  return 0;
}
