#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    n%=9;
    if(n==0)
        n=9;
    cout<<n<<"\n";
    return 0;
}