void increment_datetime(char* stamp)
{
  static const char limits[] = "99991231235959";
  int month, i = 13;
  do {
    if (stamp[i] != '9' && stamp[i] !=
        ( (i == 7) ?
            ((stamp[6] == '3' - (month == 2) &&
              (((stamp[2] << 1) ^ stamp[3]) & 3) ||
	       ((stamp[2] | stamp[3]) == '0' &&
                (((stamp[0] << 1) ^ stamp[1]) & 3) != 0)) ?
            "181010110101"[month - 1] : ('9'))
        : (i == 6 && month == 2) ?  ('2')
        : (!(i & 1) || stamp[i-1] == limits[i-1]) ? limits[i]
        : ('9'))) {
      ++stamp[i];
      break;
    }
    stamp[i] = '0';
    if ((i | 2) == 6) { stamp[i + 1] = '1'; }
    if (i == 8) { month = ((stamp[4] * 10 + stamp[5]) & 0xf); }
  } while (--i >= 0);
}

#include <iostream>
#include <string>

int main()
{
  char stamp[20];
  while (cin.getline(stamp, sizeof(stamp))) {
    increment_datetime(stamp);
    std::cout << stamp << std::endl;
  }
  return 0;
}

/* try these
19991231235959
19990228235959
20000228235959
20040229235959
20040228235959
20041228235959
*/
