#include <stdio.h> 
  
int GetRoot(int a) 
{ 
    int result = 0; 
    while (a > 0) 
    { 
        result += a%10; 
        a /= 10; 
    } 
    return result; 
} 
  
int Root(int a) 
{ 
    int result = a; 
    while (result >= 10) 
    { 
        result = GetRoot(result); 
    } 
    return result; 
} 
  
main() 
{ 
    int n=0; 
    while (1 == scanf("%d", &n) ) 
    { 
        printf("%d\n", Root(n) ); 
    } 
}