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:
/*
Written by Kabir Kanha Arora
@kabirkanha
@Kabir
 */

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

public class Main {

    static int r;
    static int c;
    static char[][] grid;

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int x = scanner.nextInt();
        while (x > 9)
            x = sumOfDigits(x);
        out.println(x);
        out.close();
    }

    static int sumOfDigits(int n) {
        int cnt = 0;
        while (n > 0) {
            cnt += n % 10;
            n /= 10;
        }
        return cnt;
    }

    static boolean isValid(Coordinate coordinate) {
        int i = coordinate.r;
        int j = coordinate.c;
        return ((i >= 0 && i < r) && (j >= 0 && j < c) && (grid[i][j] != '#'));
    }

    static class Coordinate {
        int r;
        int c;
        int dist;

        Coordinate(int r, int c, int dist) {
            this.r = r;
            this.c = c;
            this.dist = dist;
        }
    }


    // Shuffle and sort array
    static void shuffleAndSort(int[] arr) {
        for (int i = 0; i < arr.length; ++i) {
            int random_index = (int) (Math.random() * arr.length);
            int temp = arr[i];
            arr[i] = arr[random_index];
            arr[random_index] = temp;
        }
        Arrays.sort(arr);
    }

    // Fast IO
    static class FastScanner {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                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[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = nextInt();
            return a;
        }

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