Imports System
Imports System.Linq

Module Program
    Sub Main(args As String())

        Dim N As Integer = Console.ReadLine()

        Dim o As Integer = N \ 1000
        Dim p As Integer = (o + 1) * 1000
        Dim q As Integer = p - N
        If q = 1000 Then
            Console.WriteLine(0)
            Exit Sub
        End If

        Console.WriteLine(q)

    End Sub
End Module
