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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class DMCA {
	static FastReader sc = new FastReader();

	static void input(long a[]) {
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
	}

	static void input(int a[]) {
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
	}

	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;
		}
	}

	static int len(int n) {
		int c = 0;
		while (n > 0) {
			c++;
			n = n / 10;

		}
		return c;
	}

	static int sum(int n) {
		int s = 0;
		while (n > 0) {
			s += n % 10;
			n = n / 10;

		}
		return s;
	}

	public static void main(String[] args) {

		int n = sc.nextInt();
		while (len(n) > 1) {
			n = sum(n);
		}
		System.out.println(n);
	}

}