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:
/*
*	Author: CrazyDoctor
*	
*	File: B.java
*	
*	Date: 14:52:54, 01.04.2021
*/

import java.io.*;
import java.util.*;

public class B {
	public static void main(String args[]) {
		FastScanner sc = new FastScanner();
		FastPrinter fp = new FastPrinter();
		

		int n = sc.nextInt();
		int n1 = n;
		int count = 0;
		while (n1 > 0) {
			n1 /= 10;
			count++;
		}
		while (count > 1) {
			n1 = n;
			count = 0;
			int sum = 0;
			while (n1 > 0) {
				sum += n1 % 10; 
				n1 /= 10;
				count++;
			}
			n = sum;
		}
		fp.println(n);
		fp.close();
	}

	static class FastPrinter extends PrintWriter {

		FastPrinter() {
			super(System.out);
		}

		void println(int n, int[] a) {
			for (int i = 0; i < n; i++) {
				this.print(a[i] + (i == n - 1 ? "\n" : " "));
			}
		}

		void println(int n, long[] a) {
			for (int i = 0; i < n; i++) {
				this.print(a[i] + (i == n - 1 ? "\n" : " "));
			}
		}

		void println(int n, double[] a) {
			for (int i = 0; i < n; i++) {
				this.print(a[i] + (i == n - 1 ? "\n" : " "));
			}
		}

		void println(ArrayList<Object> a) {
			int n = a.size();
			for (int i = 0; i < n; i++) {
				this.print(a.get(i) + (i == n - 1 ? "\n" : " "));
			}
		}
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		
		public FastScanner() {
			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());
		}

		int[] nextIntA(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = this.nextInt();
			return a;
		}

		long[] nextLongA(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = this.nextLong();
			return a;
		}

		double[] nextDoubleA(int n) {
			double[] a = new double[n];
			for (int i = 0; i < n; i++)
				a[i] = this.nextDouble();
			return a;
		}

		ArrayList<Integer> nextIntAL(int n) {
			ArrayList<Integer> a = new ArrayList<Integer>(n);
			for (int i = 0; i < n; i++)
				a.add(this.nextInt());
			return a;
		}

		ArrayList<Long> nextLongAL(int n) {
			ArrayList<Long> a = new ArrayList<Long>(n);
			for (int i = 0; i < n; i++)
				a.add(this.nextLong());
			return a;
		}

		ArrayList<Double> nextDoubleAL(int n) {
			ArrayList<Double> a = new ArrayList<Double>(n);
			for (int i = 0; i < n; i++)
				a.add(this.nextDouble());
			return a;
		}

		ArrayList<String> nextStringAL(int n) {
			ArrayList<String> a = new ArrayList<String>(n);
			for (int i = 0; i < n; i++)
				a.add(this.next());
			return a;
		}
	}
}