        fun next() = readLine()!!
        fun nextInt() = next().toInt()
        fun nextLong() = next().toLong()
        fun nextDouble() = next().toDouble()
        fun nextList() = next().split(" ")
        fun nextIntList() = next().split(" ").map{ it.toInt() }
        fun nextLongList() = next().split(" ").map{ it.toLong() }
        fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
        fun nextListNull() = next().split("").filter { it != "" }.map{ it.toInt() }

        /* fun main(args: Array<String>){
          var a: MutableList<Int> = nextIntList().toMutableList()
          println("$a")
        } */

        // template
        /*
        A 500
        B 100
        C 50
        X 合計
         */

        // input
        /*
        30
        40
        50
        6000
         */

        // output
        /*
        213
         */

        fun main(args: Array<String>){
            val output = 0
            val n = nextInt()
            val remainder = 10000 - n

            println(remainder % 1000)
        }