Imports System
Imports System.Linq

Class Program
    Shared Sub Main(args As String())
        Dim n As Integer = CInt(Console.ReadLine())
        Dim p As Integer = n Mod 1000
    Console.WriteLine(If(p = 0, 0, 1000 - p))
    End Sub
End Class