 /*
Author: Arpit.
*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ll a;cin>>a;
  ll n=0;
  while(1){
    n=0;
    while(a!=0){
        n+=a%10;
        a/=10;
    }a=n;
    if(a<10){break;}
  }cout<<a;
  return 0;
}

