Problem: Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known.

In this problem you need to find a root of a number according to this new DMCA law.

Input

The input contains a single integer a (1 ≤ a ≤ 1000000).

Output

Output the result – an integer number.

Examples

Input


1


Output


1


Input


81


Output


9

Solution (in JAVA):

Solution:
import java.io.*;


import java.util.*;

public class Main {
	static FastReader sc=null;
	
	public static void main(String[] args) {
		sc=new FastReader();
		PrintWriter pw=new PrintWriter(System.out);
		int t=1;
		for(int o=1;o<=t;++o) {
			int n=sc.nextInt();
			int m=0;
			if(n<=9) {
				System.out.println(n);
				continue;
			}
			while(n>=10) {
				m=0;
				for(;n>=10;) {
					m+=n%10;
					n/=10;
				}
				m+=n;
				n=m;
			}
			System.out.println(m);
			
		}
		pw.close();

	}
/*                                                   中																*/
	static void put(int a[]) {
		for(int i:a) {
			System.out.print(i+" ");
		}
		System.out.println("\n");
	}
	static void copy(int a[],int b[]) {
		System.arraycopy(a, 0, b, 0, a.length);
		return;
	}
	static long gcd(long a,long b) {
		if(b==0)return a;
		else return gcd(b,a%b);
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
        int[] readArray(int n) {
    		int a[]=new int [n];
    		for(int i=0;i<n;i++) {
    			a[i]=sc.nextInt();
    		}
    		return a;
    	}
    } 
}
/*Arrays.sort(a,new Comparator<Integer>(){
				public int compare(Integer o1, Integer o2) {
					if(o1 < o2){
	                    return 1;
	                }else if(o1 > o2){
	                    return -1;
	                }
					return 0;
				}
			}
			);必须用Integer声明数组*/