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