/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
} import java.util.*; util.* java public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = 0; x 0 while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		} true {
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		} if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    } n <= 1000 n 1000 {
		        x = 1000 - n;
		        break;
		    } x = 1000 - n x 1000 - n 1000 n break; {
		        n = n - 1000;
		    } n = n - 1000 n n - 1000 n 1000 System.out.println(x) System.out.println System.out System System.out x String[] args args public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
} public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
} Main
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
}
