#include<bits/stdc++.h>
using namespace std;

#define int long long
const int T = 64;
int Digitsum(int x){
    int res  = 0;
    while(x){
        int r = x % 10;
        res+= r;
        x/=10;

    }
    return res;
}
int n;
signed main(){
    cin >> n;
    while(n>=10){
        n = Digitsum(n);

    }
    cout << n;
}
