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.InputStreamReader;

public class F {

    static class Pair {
        long a;
        long b;

        public Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        long a = getLong(reader.readLine());
        while (true) {
            long c = 0;
            while (a > 0) {
                long t = a % 10;
                c += t;
                a /= 10;
            }
            if (c >= 10) {
                a = c;
            } else {
                System.out.println(c);
                break;
            }
        }
    }

    private static int[] getArray(String readLine) {
        String strings[] = readLine.split(" ");
        int n = strings.length;
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(strings[i]);
        }
        return a;
    }

    private static long[] getLongArray(String readLine) {
        String strings[] = readLine.split(" ");
        int n = strings.length;
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(strings[i]);
        }
        return a;
    }

    private static int getInt(String s) {
        try {
            return Integer.parseInt(s);
        } catch (Exception e) {
            return 0;
        }
    }

    private static long getLong(String s) {
        try {
            return Long.parseLong(s);
        } catch (Exception e) {
            return 0;
        }
    }

    private static double getDouble(String s) {
        try {
            return Double.parseDouble(s);
        } catch (Exception e) {
            return 0;
        }
    }

}