
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto ns = readln.strip;
	writeln( solve( ns ) );
}

int solve( in string ns )
{
	auto ds = ns.map!( a => a - '0' );
	auto r = ds.sum;
	
	if( 1 < r ) return r;
	else        return solve( ( ns.to!int / 2 ).to!string ) * 2;
}

unittest
{
	assert( solve( "15" ) == 6 );
	assert( solve( "100000" ) == 10 );
}
