import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
} import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
} Main public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    } main {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    } try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        } catch(Exception e){
            System.out.println(e);
        } Exception e {
            System.out.println(e);
        } System.out.println(e) System.out.println System.out System System.out e {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            } true {
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            } N = N - 1000 N N - 1000 N 1000 if(N <= 0){
                    break;
                } N <= 0 N 0 {
                    break;
                } break; System.out.println(Math.abs(N)) System.out.println System.out System System.out Math.abs(N) Math.abs Math N String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
} Main
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            
            while(true){
                N = N - 1000;
                
                if(N <= 0){
                    break;
                }
            }
            
            System.out.println(Math.abs(N));
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
}