#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
const int MOD = 1e9 + 7;
const long long INF = 1e18 + 8;
int check(int year, int month, int day) {
  if (month == 1 || month == 2) {
    month += 12;
    year--;
  }
  int c = year / 100;
  int y = year % 100;
  int m = month;
  int d = day;
  int W = c / 4 - 2 * c + y + y / 4 + 26 * (m + 1) / 10 + d - 1;
  if (W < 0) return (W + (-W / 7 + 1) * 7) % 7;
  return W % 7;
}
bool check1(int y) {
  if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) return true;
  return false;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int y;
  cin >> y;
  int d = check(y, 1, 1);
  if (check1(y)) {
    while (1) {
      y++;
      if (check1(y) && check(y, 1, 1) == d) {
        cout << y << endl;
        return 0;
      }
    }
  } else {
    while (1) {
      y++;
      if (!check1(y) && check(y, 1, 1) == d) {
        cout << y << endl;
        return 0;
      }
    }
  }
  return 0;
}
