
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main

{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	}


}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int [] arrayIn(int n) throws IOException
	{
		int  arr[] = new int[n];
		arr[0] = 0;
		for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main

{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	}


} Main public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	} main {
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	} FastScanner fs = new FastScanner(); fs new FastScanner() int n = fs.nextInt(); n fs.nextInt() fs.nextInt fs System.out.println((1000-n%1000)%1000) System.out.println System.out System System.out (1000-n%1000)%1000 (1000-n%1000) 1000 n%1000 n 1000 1000 String args[] args class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int [] arrayIn(int n) throws IOException
	{
		int  arr[] = new int[n];
		arr[0] = 0;
		for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
} FastScanner BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer str = new StringTokenizer(""); str new StringTokenizer("") String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	} next {
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	} while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine()); !str.hasMoreTokens() str.hasMoreTokens() str.hasMoreTokens str str = new StringTokenizer(br.readLine()) str new StringTokenizer(br.readLine()) return str.nextToken(); str.nextToken() str.nextToken str int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	} nextfloat {
		return Float.parseFloat(next());
	} return Float.parseFloat(next()); Float.parseFloat(next()) Float.parseFloat Float next() next double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	} nextDouble {
		return Double.parseDouble(next());
	} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next long nextLong() throws IOException
	{
		return Long.parseLong(next());
	} nextLong {
		return Long.parseLong(next());
	} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next int [] arrayIn(int n) throws IOException
	{
		int  arr[] = new int[n];
		arr[0] = 0;
		for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	} arrayIn {
		int  arr[] = new int[n];
		arr[0] = 0;
		for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	} int  arr[] = new int[n]; arr new int[n] n arr[0] = 0 arr[0] arr 0 0 for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			arr[i] = nextInt();
		} {
			arr[i] = nextInt();
		} arr[i] = nextInt() arr[i] arr i nextInt() nextInt return arr; arr int n n public class Main

{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	}


} public class Main

{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	}


} Main

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main

{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt();
			System.out.println((1000-n%1000)%1000);
		
	}


}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int [] arrayIn(int n) throws IOException
	{
		int  arr[] = new int[n];
		arr[0] = 0;
		for(int i=1; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	
