It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.

Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000 ≤ *y* ≤ 9000) — the year number.
{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 75,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HtM3jvX0E7TZ",
        "outputId": "33ea1d79-3139-4d82-91da-0de13fcd9cb1"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1987\n",
            "2013\n"
          ]
        }
      ],
      "source": [
        "year = int(input())\n",
        "year += 1\n",
        "result = True\n",
        "\n",
        "if year >= 0 and year < 9999:\n",
        "  while True:\n",
        "    year = str(year)\n",
        "    year_digit = \"\"\n",
        "    for itm in year:\n",
        "      if itm not in year_digit:\n",
        "        year_digit += itm\n",
        "      else:\n",
        "        result = False\n",
        "        year_digit = ''\n",
        "        break\n",
        "    if result:\n",
        "      print(year)\n",
        "      break\n",
        "    else:\n",
        "      result = True\n",
        "      year = str(int(year) + 1)\n"
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "FGb5KW2UOewz",
        "outputId": "017efcff-d357-4345-c79e-af2a1e00d91a"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1\n",
            "1\n",
            "3\n",
            "3\n",
            "5\n",
            "5\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "year = str(int(input()) + 1)\n",
        "year_digit = ''\n",
        "result = False\n",
        "\n",
        "for itm in year:\n",
        "  if itm not in year_digit:\n",
        "    year_digit += itm\n",
        "  else:\n",
        "    result = False\n",
        "print(year_digit)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "6fcbUuC4agNS",
        "outputId": "838b22cc-2cb2-4ea1-e3f4-6c8b5dda8f9c"
      },
      "execution_count": 66,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1986\n",
            "1987\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "4GHvluLn5vSr"
      },
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}