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

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1; //cin >> t;
  while(t--) { 
    int n; cin >> n;
    n = n % 9;
    if(!n) n = 9;
    cout << n << '\n';
  }
  return 0;
}