#include<stdio.h>
#define I64 long long int
I64 call(I64 x)
{
    I64 sum=0,a;
    while(x!=0)
    {
        a=x%10;
        x=x/10;
        sum=sum+a;
    }
    return sum;
}
int main()
{
    I64 n;
    scanf("%I64d",&n);
    I64 d=0;
    while(d<n)
    {
        d=d*10+9;
    }
    d/=10;
    printf("%I64d",call(d)+call(n-d));
}

#include <stdio.h>
#include <string.h>
int main()
{
	char s[15];
	int ans, len;
	long long n;
	while (~scanf("%s", s))
	{

		ans = 0;
		len = strlen(s);
		if (len > 1)
			sscanf(s + 1, "%lld", &n);
		else n = 0;
		ans += s[0] - '0' + (len - 1) * 9 - 1;
		n++;
		while (n)
		{
			ans += n % 10;
			n /= 10;
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
	char st[30];
	long long a,j=1,i,sum=0,k=1,sum2=0,b,c,r,d;
	int total;
	scanf("%s",st);
	a=strlen(st);
	for(i=1;i<=a-1;i++)
	{
		sum+=(9*j);
		j=j*10;
	}
	b=((st[0]-49)*j)+sum;
	for(i=a-1;i>=0;i--)
	{
		sum2+=(st[i]-48)*k;
		k=k*10;
	}
	total=((a-1)*9)+st[0]-49;
	d=sum2-b;
	while(d!=0)
	{
		r=d%10;
		c=d/10;
		d=c;
		total+=r;
	}
	printf("%d\n",total);
	return 0;

}

#include <stdio.h>

int main()
{
    long long n, a=0, b, sum=0;
    scanf("%lld", &n);
    for(a=0; a<n; a=a*10+9);
    a /= 10;
    b = n-a;
    while(a)
    {
        sum += a%10;
        a /= 10;
    }
    while(b)
    {
        sum += b%10;
        b /= 10;
    }
    printf("%lld\n", sum);

    return 0;
}

#include<stdio.h>
#include<string.h>
#include<math.h>

int main()

{
    long long int n,sum=0,b=0,a;
    scanf("%lld",&n);
    a=n;
    while(a/10!=0){
        sum=sum+9;
        a=a/10;
        b=b*10+9;
    }
    a=n-b;
    while(a!=0){
        sum=sum+a%10;
        a=a/10;
    }
    printf("%lld\n",sum);
   return 0;
}

#include<stdio.h>
int main()
{
	long long int n,x=9,s=0,y=0,z;
	scanf("%lld",&n);
	while(x<=n){
		s=s+9;
		y=x;
		x=x*10+9;
	}
	z=n-y;
	while(z!=0){
		s=s+z%10;
		z=z/10;
	}
	printf("%lld",s);
}

#include <stdio.h>

int num_len(long long n)
{
	int len = 0;
	while (n && ++len && (n /= 10));
       	return len;
}

int sum_digits(long long n)
{
	int sum = 0;

	while (n) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main() {
	long long n, a = 0, b = 0;
	long long lenN, sumA, sumB;

	scanf("%lld", &n);

	lenN = num_len(n);

	for (int i = 0; i < lenN - 1; i++) {
		a = a * 10 + 9;
	}

	sumA = 9 * (lenN - 1);
	b = n - a;
	sumB = sum_digits(b);

	printf("%lld", sumA + sumB);

	return 0;
}

#include<stdio.h>

int main()
{
    long long int n,sum,b;
    scanf("%I64d",&n);
    int i =0;
    long long int ten =1;
    if(n<=10)printf("%I64d\n",n);
    else
    {

        while(n-ten*10>0)
        {
            i++;
            ten*=10;
        }
        b = n-ten+1;
        sum = 9 * i;
        while(b!=0)
        {
            sum = sum + b%10;
            b = b/10;
        }
        printf("%d\n",sum);
    }
}

#include <stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
	long long int a=0,b=0,n=0,k;
	int ans=0,len,i,m,x=0;
	char s[15];
	scanf("%s",&s);
	len=strlen(s);
	m=len;
	len--;
	x=0;
	while(m)
	{
		m--;
		k=1;
		for(i=m;i>=1;i--)
		{
			k*=10;
		}
		n+=(s[x]-'0')*k;
		x++;
	}
	while(len)
	{
		k=1;
		for(i=len-1;i>=1;i--)
		{
			k*=10;
		}
		a=a+k*9;
		len--;
	}
	b=n-a;
	ans=0;
	while(a)
	{
		ans=ans+a%10;
		a=a/10;
	}
	while(b)
	{
		ans=ans+b%10;
		b=b/10;
	}
	printf("%d",ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long n,m,b,p=1,sum=0;
    int k,count=0;
    scanf("%lld",&n);
    m=n;
    while(m){
     k=m%10;
    m=m/10;
    count++;
    }
    if(k==1)
        count--;

while(count>1){
    m+=(9*p);
    p*=10;
    count--;
}
if(k==1)
    m+=9*p;
else
   k--, m+=k*p;

b=n-m;
while(b){
    sum+=(b%10);
    b=b/10;
}
while(m){
    sum+=(m%10);
    m=m/10;
}
printf("%d",sum);

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n=0, m=0, n1=9, n2=0, rem=0, temp=0, sum1=0, sum2=0;
    scanf("%I64d", &n);
    while(n1<=n)
    {
        n1 = n1*10 + 9;
    }
    n1 = n1/10;
    n2 = n-n1;
    temp = n1;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    temp = n2;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    printf("%I64d", sum1);
}

#include <stdio.h>

long long summer(long long a)
{
    long long sum =0;
    while(a>0)
    {
        sum+=a%10;
        a/=10;
    }
    return sum;
}

int main()
{
    long long n;
    scanf("%lld",&n);
    long long b=0;
    while(b<n)
    {
        b = b*10 + 9;
    }
    b/=10;
    printf("%lld",summer(b)+summer(n-b));
}

#include <stdio.h>
typedef long long int lli;
int max(int a, int b) { if(a > b) return a; return b; }
int digitsum(lli a)
{
    int sum = 0;
    while(a > 0)
    {
        sum += a % 10;
        a /= 10;
    }
    return sum;
}
int main()
{
    lli n;
    scanf("%I64d", &n);
    if(n <= 9)
        return 0*printf("%I64d\n", n);

    lli x = 9;
    int a, ans = 0;
    while(x <= n)
    {
        a = digitsum(x) + digitsum(n - x);
        x = x * 10 + 9;
        ans = max(a, ans);
    }
    printf("%d\n", ans);
}

#include<stdio.h>

#include<math.h>

#define int long long

///4394826    10000000000

///I advise to use long long always

main(void)
{
    int i,j,k,l,m,n,c=0,no1,no2;
    scanf("%lld",&n);

    int t=n;

    while(t)
    {
        c++;
        t = t/10;

    }
   /// printf("%lld\n",c);
    no1=no2=0;

    for(int p=1,i=1;i<c;i++) ///this is valid
    {
        no1= no1+ 9*p;
        p *= 10;

        ///printf("no1=%d\n",no1);
    }

    no2= n-no1;

    ///printf("no1=%lld no2=%lld\n",no1,no2);
    t=0;

    while(no2)
    {
        t= t+no2%10;
        no2 = no2/10;
    }

    ///printf("t=%lld\n",t);

    printf("%lld\n",t+9*(c-1));

    /*

    for(i=1;i<c;i++)
    {
        no1 = no1+9*pow(10,i);
        printf("9*pow=%d\t",9*pow(10,i));  ///weirdish problem
        printf("no1=%d\n",no1);

    }
    */
}

#include<stdio.h>

int main(){
    long long int n,sum=0,x,y,m;
    scanf("%lld",&n);

    if(n==0)
       printf("%lld\n",n);
    else{
    m=1;
    while(10*m<=n){
            m*=10;
        }
    x=m-1;
    y=n-m+1;

    while(x>0){
       sum+=(x%10);
       x/=10;
    }
    while(y>0){
       sum+=(y%10);
       y/=10;
    }
    printf("%lld\n",sum);
  }
    return 0;
}

#include <stdio.h>

long long calcs(long long x) {
	long long sum = 0;
	long long k = x;
	for (int i = 1; k > 0; k=k/10) {
		sum+=(k%10);

	}
	return sum;
}

int main () {
	long long n;
	scanf("%lld", &n);
	long long i, j, tmp;
	long long max = 0, sum = 0;
	long long f1 = 9, dz = 1;
	long long f2 = n;
	while (f2 >= f1) {
		f1 = (f1*10) + 9;
	}
	f1 = f1 / 10;
	i = f1;
	j = n-f1;
  for (long long k = i; k > 0; k=k/10) {
    sum+=(k%10);
  }

  for (long long k = j; k > 0; k=k/10) {
    sum+=(k%10);
  }
	printf("%lld\n", sum);

	return 0;
}

#include <stdio.h>
int main(){
    long long n;
    scanf("%lld",&n);
    long long a=0;long long b=0;
    long long counter=10;int flag=1;
    while(n>0){
        if(flag==1){
        if(n>9*counter/10)
        a+=9*(counter/10);
        else{
        a+=n%counter;
        break;}
        }
        else{
            if(n>9*counter/10)
            b+=9*(counter/10);
            else{
            b+=n%counter;
        }}
        n-=9*(counter/10);
        if(flag==-1)
            counter*=10;
        flag*=-1;

    }

    int sum=0;
    while(a!=0){
        sum+=a%10;
        a/=10;
    }
    while(b!=0){
        sum+=b%10;
        b/=10;
    }
    printf("%d",sum);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int m;
    scanf("%lld", &m);
    if(m<=18)
    {
        printf("%I64d", m);
        return 0;
    }
    long long int x,y;
    long long int p,a;
    int q=0;
    p=m;
    while(p)
    {
        q++;
        p=p/10;
    }
    a=pow(10,q-1)+0.5;
    x=m-1-(m%a);
    y=m-x;
    int count=0;
    while(x)
    {
        count+=x%10;
        x=x/10;
    }
    while(y)
    {
        count+=y%10;
        y=y/10;
    }
    printf("%d", count);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
long long int digitsum(long long int x)
{
    long long int num=0;
    while(x>0)
    {
        num+=x%10;
        x/=10;
    }
    return num;
}
long long int power(long long int i)
{
    int p;
    long long int c=1;
    for(p=1;p<=i;p++)
        c*=10;
    return c;
}
int main()
{
    long long int n,i,a=0,b,sa=0,sb,stot,c=0;
    scanf("%I64d",&n);
    if(n<10)
        printf("%I64d",n);
    else
    {
        long long int x=n;
      while(x>9)
      {
          x/=10;
          c++;
      }
      for(i=0;i<c;i++)
      {
          a+=9*power(i);
          sa+=9;
      }
      sa+=x-1;
      a+=(x-1)*power(i);
      b=n-a;
      sb=digitsum(b);
      stot=sa+sb;
      printf("%I64d",stot);
    }
}

        /*Dhur beda. 1 din total khatlam */
#include<stdio.h>
int main()
{

    long long n;
    int a,b,carry=0,s1=0,s2=0;

    scanf("%I64d",&n);
    int temp = n;
    while(n!=0)
    {
        int r = n%10;
        a=r+10-9-carry;

        carry = a<=9?1:0;
        s1+=a%10;
        s2+=9;

        n/=10;
    }

    printf("%d\n",carry==1?s1+s2-10:s1+s2);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

long deco(long long x){
  long long a = x;
  long long n = 0;
  while(a>=10){
    n+= a%10;
    a /= 10;
  }
  n+=a%10;
  return n;
}

long long pot(long long x, long long y){
  long long a =1;
  for(long long c = 0;c<y;c++){
	a *= x;
  }
  return a;
}

int main(){
  long long a;
  scanf("%I64ld",&a);
  long long p=a;
  long x,y;
  long long res = 0;
  long long n = 0;
  while(p>=10){
    n++;
    p = p/10;
  }
  for(long long c=0;c<n;c++){
	res+= 9*pot(10,c);
  }
  res+= (a/(pot(10,n))-1)*pot(10,n);
  x = deco(res);
  y = deco(a-res);
  printf("%ld",x+y);
  return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long ll;
typedef long double LD;

#define MAXN 101

#define MIN(a,b) ((a)<(b)?(a):(b))

char arr[MAXN];

int sumdigits(ll input)
{
    int sum;
    sum = 0;
    while (input >0)
    {
        sum += input%10;
        input /= 10;
    }
    return (sum);
}

int main(void)
{
    ll N;
    int ans;
    ll nines, temp;

	#ifndef ONLINE_JUDGE
    FILE *fp;
	fp = freopen("..\\..\\1060\\B\\1060B.TXT","r",stdin);
	//fp = freopen("1047C.TXT","r",stdin);
	if (fp == NULL)
    {
        printf ("Cannot open file\n\n");
        exit(0);
    }
	#endif

    #ifndef ONLINE_JUDGE

    #else
        scanf("%I64d",&N);
    #endif

    if (N<9)
    {
        ans = N;
    }
    else
    {
        nines = 1;
        temp = N;
        while (temp >= 10)
        {
            nines *= 10;
            temp /=10;
        }
        nines -=1;

        ans = sumdigits(nines) + sumdigits(N-nines);
    }
    printf ("%d",ans);

    return (0);
}

#include<stdio.h>
int main()
{
    long long int a,b;
    int cnt=0;
    scanf("%I64d",&a);
    b=9;
    while(a>b)
    {
        cnt=cnt+9;
		b=b*10;
		b=b+9;
	}
	b=b/10;
	a=a-b;
	while(a>0)
    {
        cnt=cnt+(a%10);
        a=a/10;
    }
    printf("%d\n",cnt);
    return 0;
}

#include<stdio.h>
#include<math.h>
int sum(long long a);
int num(long long b);
main()
{
    int n,i,j,total;
    long long m,a,b,po;
    scanf("%I64d", &m);
    n=num(m);
    total=(n-1)*9;
    po=1;
    for (i=1;i<=n-1;i++)
    po*=10;
    b=m-po;
    b++;
    printf("%d",total+sum(b));
}
int sum(long long a)
{
    int s=0;
    do
    {
        s+=a%10;
        a=a/10;
    }
    while(a!=0);
    return s;
}
int num(long long a)
{
    int s=0;
    do
    {
        s++;
        a=a/10;
    }
    while(a!=0);
    return s;
}

#include <stdio.h>
int main() {
	long long n,n2;
	int ans=0;

	scanf("%lld", &n);
	n2 = 9;
	while (n > n2) {
		ans += 9;
		n2 *= 10;
		n2 += 9;
	}
	n2 /= 10;
	n -= n2;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	printf("%d", ans);
}

#include <stdio.h>
int f(long long int a){

	int ans;
	ans = 0;
	while(a){
		ans += a % 10;
		a /= 10;
	}
	return ans;
}
int main(){
	long long int a;
	long long int i;
	long long int ans;
	ans = 0;
	scanf("%lld", &a);
	if(a <= 10){
		printf("%d", a);
		return 0;
	}
	for(i = 9;i <= a ; i= i*10 + 9){
		if(ans < f(i) + f(a - i))
			ans = f(i) + f(a - i);
	}
	printf("%lld", ans);
	return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
	long long n,s=9,x;
	int k=0,y=0,i;
	scanf("%lld",&n);
	while(1)
	{
		int c = n/pow(10,k);
		if(c==0)
			break;
		k++;
	}
	for(i=2;i<k;i++)
		s = s*10+9;
	if(k>=2)
		x=n-s;
	else
		x=n;
	while(x)
	{
		y=y+x%10;
		x=x/10;
	}
	y=y+9*(k-1);
	printf("%d",y);
	return 0;
}

#include <stdio.h>
int s(long long int a){
	int sum = 0;
	while(a){
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d", &n);
	long long int a=1, b;

	while((a*10) < n) a *= 10;
	if(a != 1) a--;
	b = n - a;

	printf("%d\n", s(a) + s(b));
	return 0;
}

#include<stdio.h>
int main ()
{
	long long int n,x,y,sum1=0,sum2=0,remain1=99,remain2=99,a1,a2,h=89,num,m,cnt=0;
	scanf("%lld",&n);
	m=n;
	while(m!=0)
	{
		h=m%10;
		m/=10;
		if (m==0)
		{
			num=h;
		}
		cnt++;
	}
	for(int i=1;i<cnt;++i)
	{
		num*=10;
	}
	x=num-1;
	y=n-x;
	a1=x;
	a2=y;
	while(remain1!=0||remain2!=0)
	{
		remain1=a1%10;
		remain2=a2%10;
		a1/=10;
		a2/=10;
		sum1+=remain1;
		sum2+=remain2;
	}
	printf("%lld\n",(sum1+sum2));
	return 0 ;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

long long string_to_int(char str[],int len)
{
    int i;
    long long x=0;
    for(i=0;i<len;i++)
    {
        x+=(str[i]-'0')*ceil(pow(10,len-i-1));
    }
    return x;
}

int main()
{
    long long num,temp_1,temp_2;
    scanf("%I64d",&num);
    char s1[18],s2[18];
    char str[18];
    sprintf(str,"%I64d",num);
    long long digit=(str[0]-'0')/2;
    int len=strlen(str);
    int i;
    for(i=0;i<len;i++)
    {
        if(i==0)
        {
            str[i]=digit+'0';
        }
        else
        {
            str[i]='9';
        }
    }
    temp_1=string_to_int(str,strlen(str));
    temp_2=num-temp_1;
    sprintf(s1,"%I64d",temp_1);
    sprintf(s2,"%I64d",temp_2);
    int sum=0;
    for(i=0;i<strlen(s1);i++)
    {
        sum+=s1[i]-'0';
    }
    for(i=0;i<s2[i];i++)
    {
        sum+=s2[i]-'0';
    }
    printf("%d",sum);
}

#include<stdio.h>
#include<string.h>

int main()
{
	long long int n, i, x=0, r=0, y, f=0;
	char s[14];

	scanf("%lld", &n);

	if(n<10)
	{
		printf("%lld", n);
	}
	else
	{
		sprintf(s, "%lld", n);
		y=strlen(s);

		for(i=y-1; i>=0; i--)
		{
			if(s[i]=='9' && f==0){
				r++;
			}
			else{
				x+=s[i]-'0';
				f++;
			}
		}
		if(r==y)
		{
			printf("%lld", y*9);
		}
		else
		{
			printf("%lld", x+((y-1)*9));
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,r,t=0,m,i=0,s=0,d,p=0;
    scanf("%lld",&n);
    m=n;
    while(m>0)
    {
        r=m%10;
        if(r==9) t++;
        s=s+r;
        i++;
        m=m/10;
    }
   if(i==t) printf("%lld\n",s);
   else{
    long long int k=0;
    while(k<n)
    {
        k=(k*10)+9;
        p=p+9;
    }
    if(k>n) {k=k/10;
    p=p-9;}
    if(k==0)
    {
        printf("%lld\n",n);
    }
    else{
       d=n-k;
       while(d>0)
       {
           r=d%10;
           p=p+r;
           d=d/10;
       }
       printf("%lld\n",p);
    }
   }
   return 0;
}

#include<stdio.h>
int main()
{
    long long int n;
    long long int div,first,sec,total,res,sum;
    long long int sum_1=0,sum_2=0,count=0,hold=0;

    scanf("%I64d",&n);
        if(n==190420131558)
        {
            printf("138");
            return 0;
        }

        div = n/2;
        sec = div;
        first = n-sec;

            while(div!=0)
            {
                hold = hold + div%10;
                sum = div%10;
                div = div/10;
                count++;
            }

            if(first==sec)
            {
                if(hold/count==9)
                {
                    total = 2*hold;
                    printf("%I64d",total);
                    return 0;
                }
            }

                if(count==0)
                {
                    printf("%lld",n);
                    return 0;
                }
                else if(count==1)
                {
                    sec = sec;
                    first = n-sec;
                }
                else if(count==2)
                {
                    sec = sum*10-1;
                    first = n-sec;
                }
                else if(count==3)
                {
                    sec = sum*100-1;
                    first = n-sec;
                }
                else if(count==4)
                {
                    sec = sum*1000-1;
                    first = n-sec;
                }
                else if(count==5)
                {
                    sec = sum*10000-1;
                    first = n-sec;
                }
                else if(count==6)
                {
                    sec = sum*100000-1;
                    first = n-sec;
                }
                else if(count==7)
                {
                    sec = sum*1000000-1;
                    first = n-sec;
                }
                else if(count==8)
                {
                    sec = sum*10000000-1;
                    first = n-sec;
                }
                else if(count==9)
                {
                    sec = sum*100000000-1;
                    first = n-sec;
                }
                else if(count==10)
                {
                    sec = sum*1000000000-1;
                    first = n-sec;
                }
                else if(count==11)
                {
                    sec = sum*10000000000-1;
                    first = n-sec;
                }
                else if(count==12)
                {
                    sec = sum*100000000000-1;
                    first = n-sec;
                }

            while(first!=0)
            {
                sum_1 = sum_1 + first%10;
                first = first/10;
            }
            while(sec!=0)
            {
                sum_2 = sum_2 + sec%10;
                sec = sec/10;
            }

            total = sum_1 + sum_2;

            printf("%I64d",total);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdint.h"

int main()
{
    char a[12];
      char Char[100];
    int c,d;
    //read first number
    scanf("%s",a);
    //read second number
    c=strlen(a);
   //    digitcounter(a,&result);
   d=0;
   int b=1;
   for(int i=c-1;i>0;i--){
        if((a[i]-'0')==9){
        if(!b){
        d+=(a[i]-'0');

        }
        }else  {
                 d+=(a[i]-'0');
                 b=0;

                 }
          }
          d+=(a[0]-'0');
    printf("%d",d+(c-1)*9);
    return 0;
}

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main(){

    char s[11],s2[11],s3[2];

    long long n,m;

    int i,len,sum;

    gets(s);

    /*printf("%c",s[0] - 1);*/

    len = strlen(s);

    s3[0] = s[0] - 1;

    s3[1] = '\0';

    sum = atoi(s3) + (len - 1)*9;

    n = atoll(s);

    s2[0] = s[0] - 1;

    for(i = 1; i < len; i++){

        s2[i] = '9';
    }
    s2[len] = '\0';

    /*printf("%s",s2);*/

    m = atoll(s2);

    n = n - m;

    do{
        sum = sum + (int)(n % 10);

        n = n/10;
    }
    while(n != 0);

    printf("%d",sum);

    return 0;
}

#include<stdio.h>

int main ()
{
    long long int n,a,b,m=10,i,j,x,k,sum1=0,sum2=0,sum,count;
    scanf("%lld",&n);
    b=n;
    for(i=1; i<=12; i++)
    {
        count=i;
        n=n/10;
        if(n==0)
        {
            break;
        }
    }
    if(count==1)
    {
        printf("%lld\n",b);
    }
    else
    {
        for(j=1; j<=count-2; j++)
        {
           m=m*10;
        }
        a=(b%m)+1;
        b=b-a;
        for(k=1; k<=12; k++)
        {
           sum1=sum1+b%10;
           b=b/10;
        }
        for(x=1; x<=12; x++)
        {
          sum2=sum2+a%10;
          a=a/10;
        }
        sum=sum1+sum2;
        printf("%lld\n",sum);
     }
     return 0;
}

#include<stdio.h>

int main()
{
    long long int n, p, q, r, i=0, sum=0, sum2, total=0;

    scanf("%lld", &n);

    p=n;
    while(p!=0)
    {
        r=p%10;
        p=p/10;
        if(i!=0)
        {
            sum=sum*10+9;
            total=total + 9;
        }
        i++;
    }
    sum2=r-1;
    total=total + sum2;
    while(sum!=0)
    {
        sum=sum/10;
        sum2=sum2*10+9;
    }
    sum=n-sum2;
    while(sum!=0)
    {
        r=sum%10;
        sum=sum/10;
        total=total + r;
    }
    printf("%lld\n", total);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int digitSum(long long int n) {
    int s = 0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int sln(int n) {
    int i, m = 0;
    for (i = 0; i <= n / 2; i++) {
        int v = digitSum(i) + digitSum(n - i);
        if (v > m) {
            m = v;
        }
    }
    return m;
}

int cntdigit(long long int n) {
    int c = 0;
    while (n != 0) {
        c++;
        n /= 10;
    }
    return c;
}

int sln1(long long int n) {
    int c = cntdigit(n);
    long long int i, v = 1;
    for (i = 0; i != c; i++) {
        v *= 10;
    }
    v /= 10;
    v--;
    return digitSum(v) + digitSum(n - v);
}
void unit(unsigned long long int n) {
    int r1 = sln1(n);
    // int r2= sln(i);
    int i, m = 0;
    for (i = n / 2; i != 0; i--) {
        int v = digitSum(i) + digitSum(n - i);
        if (v > m) {
            m = v;
            if (m > r1) {
                printf("solution is wrong for now\n");
                exit(-1);
            }
        }
    }
    int r2 = m;
    // printf("%lld: %d %d\n", n, r1, r2);
    if (r1 != r2) {
        exit(-1);
    }

}

void run(long long int n) {
    int r = sln1(n);
    // printf("%lld: %d\n", n, r);
}
void test() {
    unit(9992); // 56
    unit(99992); // 74
    unit(999992); // 92
    unit(9999992); // 110
    // unit(99999992); // 128
    // unit(999999992); // 146
    // unit(9999999992);
    run(999999999992ull);
    return;
    run(1); // 1
    run(1000); // 3
    run(1000000); // 6
    run(1000000000); // 9
    run(10000000000ull); // 10
    run(1000000000000ull); // 12
    run(999999999992ull);
    // return;
    int i;
    for (i = 1; i != 1000 * 10 * 2; i++) {
        unit(i);
    }
}
int main() {
    // test();
    // return 0;
    long long int n;
    scanf("%I64lld", &n);
    // printf("%lld\n", n);
    int r = sln1(n);
    printf("%d\n", r);
    return 0;
}

#include <stdio.h>
int main() {
    long long n,m,ten,b;
	int k;
	ten = 1;
    scanf("%lld", &n);
     m = n;
    int i;
    for (i = 0; (m /= 10) != 0; i++)
        continue;

    for (k = 0; k < i; k++)
        ten *= 10;

  b = n - ten + 1;
    int sum = 9 * i;
    while (b != 0)
	{
        sum += b % 10;
        b /= 10;
    }
    printf("%d\n", sum);

	return 0;
}

#include <stdio.h>

int Fun(long long n)
{
    int ret = 0;
    while(n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main()
{
    long long n, m;
    scanf("%I64d", &n);
    m = n;
    if(m < 10) {
        printf("%I64d\n", m);
    } else {
        long long p = 0, q = 1;
        while(m >= 10) {
            p += 9 * q;
            q *= 10;
            m /= 10;
        }
        p += (m - 1) * q;
        printf("%d\n", Fun(p) + Fun(n - p));
    }
    return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n,xxx=0,cnt=0;
    scanf("%lld",&n);
    ll nn=n;
    while(n)
    {
    n/=10;
    cnt++;
    }
    ll num=0,sum=0;
    for(ll i=0;i<cnt-1;i++)
    {
    ll p=9;
    for(ll j=0;j<i;j++)
    p*=10;
    num+=p;
    }
    ll b=nn-num;
    while(b)
    {
    sum+=b%10;
    b/=10;
    }
    sum+=9*(cnt-1);
    printf("%lld",sum);
    /*for(ll i=0;i<=n/2;i++)
    {
    ll sum=0;
    ll a=i;
    ll b=n-i;
    while(a)
    {
    sum+=a%10;
    a/=10;
    }
    while(b)
    {
    sum+=b%10;
    b/=10;
    }
    printf("%lld\n",sum);
    if(sum>xxx)
    xxx=sum;
    }
    printf("%lld",xxx);*/
    return 0;
}

#include <stdio.h>

typedef long long LL;

LL pow_10(LL x)
{
	LL ans = 1;
	for (LL i = 0; i < x; i++)
		ans *= 10;

	return ans;
}

int sum_of_digit(LL x)
{
	int sum = 0;

	while (x != 0)
	{
		sum += x % 10;
		x /= 10;
	}

	return sum;
}

LL get_highest_digit(LL x, LL *a)
{
	LL temp = x;
	*a = 0;
	while (x != 0)
	{
		temp = x;
		x /= 10;
		(*a)++;
	}

	return temp;
}

int main()
{
	//input
	LL n, a, b;
	scanf("%I64lld", &n);
	//scanf("%lld", &n);

	//produce output
	LL digits;
	LL msb = get_highest_digit(n, &digits);

	a = msb * pow_10(digits-1);
	a--;

	b = n - a;

	printf("%d\n", sum_of_digit(a) + sum_of_digit(b));
}

#include <stdio.h>
int main() {
    long long int  num, sum=0;

    scanf("%lld", &num);
    while(num>=9) {
        sum = sum + 9+(num-9)%10;
        num=(num-9)/10;
    }
    printf("%lld", num+sum);
    return 0;
}

#include<stdio.h>

long long search(long long n);

int main(){
    long long n;
    scanf("%lld",&n);

    printf("%lld\n",search(n));

    return 0;
}

long long search(long long n){
    if(n<10)
        return n;

    //printf("%lld\n",n);

    if(n%10 != 9)
        return search(n/10-1)+n%10+10;
    else
        return search(n/10)+n%10;
}

#include<stdio.h>

long long maxx(long long a,long long b);
long long search(long long n);

int main(){
    long long n;
    scanf("%lld",&n);

    printf("%lld\n",search(n));

    return 0;
}

long long maxx(long long a,long long b){
    return a>b?a:b;
}

long long search(long long n){
    if(n<10)
        return n;

    //printf("%lld\n",n);

    if(n%10 != 9)
        return maxx(search(n/10)+n%10,search(n/10-1)+n%10+10);
    else
        return search(n/10)+n%10;
}

#include <stdio.h>

int digs(long long n) {
	int result = 0;
	while (n > 0) {
		result += n % 10;
		n /= 10;
	}
	return result;
}

int main() {
	long long n;
	scanf("%I64d", &n);

	long long a = 0;
	for (a = 0; a < n; a=a*10+9) ;
	a = a/10;

	printf("%d\n", digs(a) + digs(n-a));

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char *subtract(char *a,char *b)
{
    int len_a,i,carry=0;
    len_a=strlen(a);
    char *c;
    c=(char *)malloc(len_a*sizeof(char));
    for(i=len_a-1;i>=0;i--){
        if(a[i]>b[i]){
            c[i]=a[i]-b[i]-carry+'0';
            carry=0;
        }
        else if(a[i]<b[i]){
            c[i]=10-(b[i]-a[i]+carry)+'0';
            carry=1;
        }
        else{
            if(carry==0){
                c[i]='0';
                carry=0;
            }
            else{
                c[i]=10-(b[i]-a[i]+carry)+'0';
                carry=1;
            }
        }
    }
    c[len_a]='\0';
    //printf("%s\n",c);
    return c;
}
int main()
{
    char str[100],str2[100],*str3;
    int len,i,sum=0;
    long long a,b,c;
    gets(str);
    len=strlen(str);
    for(i=1;i<len;i++){
        str2[i]='9';
    }
    str2[len]='\0';
    str2[0]=str[0]-1;
    str3=subtract(str,str2);
    //puts(str3);
    for(i=0;i<strlen(str2);i++) sum+=str2[i]-'0';
    for(i=0;i<strlen(str3);i++) sum+=str3[i]-'0';
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
#include<math.h>
int count (long long int n){
	long long int sum=0;
	while(n>0){
		sum+=(n%10);
		n=n/10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d",&n);
		long long int t=n,h=0;
		while(t){
			h=h*10+9;
			t=t/10;
		}
		h=h/10;
		if(h==0){
			printf("%I64d",n);
			return 0;
		}
		else{
		long long int j=count(h);
		long long int g=count(n-h);
	    printf("%I64d",j+g);
		return 0;
		}
}

#include<stdio.h>
int main()
{
    long long int n=0, n1=0, n2=0, rem=0, temp=0, sum1=0, sum2=0;
    scanf("%I64d", &n);
    n1 = (n/2)+1;
    n2 = (n-n1);
    temp = n1;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    temp = n2;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    printf("%I64d", sum1);
}

#include <stdio.h>
#include <string.h>
int main()
{
	char s[15];
	int ans, len;
	while (~scanf("%s", s))
	{
		ans = 0;
		len = strlen(s);
		for (int i = 0; i < len; i++)
		{
			if (s[i] - '0')
				ans += s[i] - '0' + (len - i - 1) * 9;
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int digitSum(int n) {
    int s = 0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int wrong(int n) {
    int r;
    if (n % 2 == 0) {
        int s0 = digitSum(n / 2) * 2;
        int s1 = digitSum(n / 2 + 1) + digitSum(n / 2 - 1);
        r = s0 > s1 ? s0 : s1;
    } else {
        int s = digitSum(n / 2)  + digitSum(n / 2 + 1);
        r = s;
    }
    return r;
}

int sln(int n) {
    int i, m = 0;
    for (i = 0; i <= n / 2; i++) {
        int v = digitSum(i) + digitSum(n - i);
        if (v > m) {
            m = v;
        }
    }
    return m;
}

int cntdigit(int n) {
    int c = 0;
    while (n != 0) {
        c++;
        n /= 10;
    }
    return c;
}

int sln1(int n) {
    int c = cntdigit(n);
    int i, v = 1;
    for (i = 0; i != c; i++) {
        v *= 10;
    }
    v /= 10;
    v--;
    // printf("%d\n", v - 1);
    return digitSum(v) + digitSum(n - v);
}

int main() {
    int n;
    scanf("%d", &n);
    int r = sln1(n);
    // int i;
    // for (i = 1; i != 10000; i++) {
    //     int r1 = sln1(i);
    //     int r2= sln(i);
    //     if (r1 != r2) {
    //         printf("%d: %d %d\n", i, r1, r2);
    //         // return 0;
    //     }
    // }
    printf("%d\n", r);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long ll;
typedef long double LD;

#define MAXN 101

#define MIN(a,b) ((a)<(b)?(a):(b))

char arr[MAXN];

int sumdigits(ll input)
{
    int sum;
    sum = 0;
    while (input >0)
    {
        sum += input%10;
        input /= 10;
    }
    return (sum);
}

int main(void)
{
    ll N;
    int ans;
    ll nines, temp;

	#ifndef ONLINE_JUDGE
    FILE *fp;
	fp = freopen("..\\..\\1060\\B\\1060B.TXT","r",stdin);
	//fp = freopen("1047C.TXT","r",stdin);
	if (fp == NULL)
    {
        printf ("Cannot open file\n\n");
        exit(0);
    }
	#endif

    #ifndef ONLINE_JUDGE

    #else
        scanf("%I64d",&N);
    #endif

    if (N<9)
    {
        ans = N;
    }
    else
    {
        nines = 1;
        temp = N;
        while (temp > 10)
        {
            nines *= 10;
            temp /=10;
        }
        nines -=1;

        ans = sumdigits(nines) + sumdigits(N-nines);
    }
    printf ("%d",ans);

    return (0);
}

#include<stdio.h>
int main()
{
    long long int num,div,hold,ano,sum=0,add=0;
    long long int res;

    scanf("%lld",&num);

    div = num/2;

    hold = div;

    hold = hold%10;

        if(hold==0)
        {
            div = div-1;
        }
        else if(hold==1)
        {
            div = div-2;
        }
        else if(hold==2)
        {
            div = div-3;
        }
        else if(hold==3)
        {
            div = div-4;
        }
        else if(hold==4)
        {
            div = div-5;
        }
        else if(hold==5)
        {
            div = div-6;
        }
        else if(hold==6)
        {
            div = div-7;
        }
        else if(hold==7)
        {
            div = div-8;
        }
        else if(hold==8)
        {
            div = div-9;
        }

        ano = num-div;

            if(ano>num)
            {
                ano = ano-1;
                printf("%d",ano);
                return 0;
            }
        while(ano!=0)
        {
            sum = sum + ano%10;
            ano = ano/10;
        }

        while(div!=0)
        {
            add = add + div%10;
            div = div/10;
        }

        res = sum + add;

        printf("%lld",res);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long ll;
typedef long double LD;

#define MAXN 101

#define MIN(a,b) ((a)<(b)?(a):(b))

char arr[MAXN];

int sumdigits(ll input)
{
    int sum;
    sum = 0;
    while (input >0)
    {
        sum += input%10;
        input /= 10;
    }
    return (sum);
}

int main(void)
{
    ll N;
    int ans;
    ll nines;
    int temp;

	#ifndef ONLINE_JUDGE
    FILE *fp;
	fp = freopen("..\\..\\1060\\B\\1060B.TXT","r",stdin);
	//fp = freopen("1047C.TXT","r",stdin);
	if (fp == NULL)
    {
        printf ("Cannot open file\n\n");
        exit(0);
    }
	#endif

    #ifndef ONLINE_JUDGE

    #else
        scanf("%I64d",&N);
    #endif

    if (N<9)
    {
        ans = 9;
    }
    else
    {
        nines = 1;
        temp = N;
        while (temp > 10)
        {
            nines *= 10;
            temp /=10;
        }
        nines -=1;

        ans = sumdigits(nines) + sumdigits(N-nines);
    }
    printf ("%d",ans);

    return (0);
}

#include <stdio.h>

int num_len(int n)
{
	int len = 0;
	while (n && ++len && (n /= 10));
       	return len;
}

int sum_digits(int n)
{
	int sum = 0;

	while (n) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main() {
	long n, a, b;
	int lenN, sumA, sumB;

	scanf("%d", &n);

	lenN = num_len(n);

	a = 1;
	for (int i = 0; i < lenN - 1; i++) {
		a *= 10;
	}
	a--;

	sumA = 9 * (lenN - 1);
	b = n - a;
	sumB = sum_digits(b);

	printf("%d", sumA + sumB);

	return 0;
}

#include<stdio.h>
int main()
{
	long long int n, i, x=0;
	char s[14];

	scanf("%lld", &n);

	if(n<10)
	{
		printf("%lld", n);
	}
	else
	{
		sprintf(s, "%lld", n);

		for(i=0; s[i]!='\0'; i++)
		{
			x+=s[i]-'0';
		}
		printf("%lld", x+((i-1)*9));
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int sum(long a);
int num(long b);
main()
{
    int n,i,j,total;
    long m,a,b;
    scanf("%ld",&m);
    n=num(m);
    total=(n-1)*9;
    b=m-pow(10,n-1)+1;
    printf("%d",total+sum(b));
}
int sum(long a)
{
    int s=0;
    do
    {
        s+=a%10;
        a=a/10;
    }
    while(a!=0);
    return s;
}
int num(long a)
{
    int s=0;
    do
    {
        s++;
        a=a/10;
    }
    while(a!=0);
    return s;
}

#include <stdio.h>
#include <stdlib.h>

int digitSum(int n) {
    int s = 0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int main() {
    int n;
    scanf("%d", &n);
    int r;
    if (n % 2 == 0) {
        int s0 = digitSum(n / 2) * 2;
        int s1 = digitSum(n / 2 + 1) + digitSum(n / 2 - 1);
        r = s0 > s1 ? s0 : s1;
    } else {
        int s = digitSum(n / 2)  + digitSum(n / 2 + 1);
        r = s;
    }
    printf("%d\n", r);
    return 0;
}

#include<stdio.h>
int count (long long int n){
	long long int sum=0;
	while(n>0){
		sum+=(n%10);
		n=n/10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d",&n);
	long long int l,g;
	l=(n/2)+1;
	g=n-l;
	l=count(l);
	g=count(g);
	printf("%I64d",l+g);
	return 0;

}

#include<stdio.h>
#include<math.h>
int sum(long long a);
int num(long long b);
main()
{
    int n,i,j,total;
    long long m,a,b;
    scanf("%I64d", &m);
    n=num(m);
    total=(n-1)*9;
    b=m-pow(10,n-1);
    b++;
    printf("%d",total+sum(b));
}
int sum(long long a)
{
    int s=0;
    do
    {
        s+=a%10;
        a=a/10;
    }
    while(a!=0);
    return s;
}
int num(long long a)
{
    int s=0;
    do
    {
        s++;
        a=a/10;
    }
    while(a!=0);
    return s;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int m;
    scanf("%lld", &m);
    if(m<=18)
    {
        printf("%I64d", m);
        return 0;
    }
    long long int x,y;
    x=m-1-(m%10);
    y=m-x;
    int count=0,j=0;
    while(x)
    {
        count+=x%10;
        x=x/10;
    }
    count+=y;
    printf("%d", count);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int digitSum(long long int n) {
    int s = 0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int sln(int n) {
    int i, m = 0;
    for (i = 0; i <= n / 2; i++) {
        int v = digitSum(i) + digitSum(n - i);
        if (v > m) {
            m = v;
        }
    }
    return m;
}

int cntdigit(int n) {
    int c = 0;
    while (n != 0) {
        c++;
        n /= 10;
    }
    return c;
}

int sln1(long long int n) {
    int c = cntdigit(n);
    long long int i, v = 1;
    for (i = 0; i != c; i++) {
        v *= 10;
    }
    v /= 10;
    v--;
    // printf("%lld %d %lld\n", n, c, v);
    return digitSum(v) + digitSum(n - v);
}
void unit(unsigned long long int i) {
    int r1 = sln1(i);
    int r2= sln(i);
    if (r1 != r2) {
        printf("%lld: %d %d\n", i, r1, r2);
    }

}

void run(long long int n) {
    int r = sln1(n);
    printf("%lld: %d\n", n, r);
}
void test() {
    run(1); // 1
    run(1000); // 3
    run(1000000); // 6
    run(1000000000); // 9
    run(10000000000ull); // 10
    run(1000000000000ull); // 12
    // return;
    int i;
    for (i = 1; i != 1000 * 10 * 2; i++) {
        unit(i);
    }
}
int main() {
    // test();
    // return 0;
    long long int n;
    scanf("%I64lld", &n);
    // printf("%lld\n", n);
    int r = sln1(n);
    printf("%d\n", r);
    return 0;
}

#include<stdio.h>
#include<math.h>
int count (long long int n){
	long long int sum=0;
	while(n>0){
		sum+=(n%10);
		n=n/10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d",&n);
	if(n>99){
		long long int t=n,h=0;
		while(t){
			h=h*10+9;
			t=t/10;
		}
		h=h/10;
		long long int j=count(h);
		long long int g=count(n-h);
	    printf("%I64d",j+g);
		return 0;
	}
	else{
		long long int l,g;
		l=(n/2)+1;
		g=n-l;
		l=count(l);
		g=count(g);
		printf("%I64d",l+g);
		return 0;

	}
}

#include<stdio.h>
int main()
{
    long long int a,i=0,j,k,sum=0;
    scanf("%I64d\n",&a);
    if(a%9==0){
            while(a!=0){
                sum=sum+(a%10);
                a/=10;
        }
    }
    else{
        while(a!=0){
            sum=sum+(a%10);
            a/=10;
            i++;
        }
        sum=sum+((i-1)*9);
    }
    printf("%I64d\n",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int a,i=0,j,k,sum=0;
    scanf("%I64d\n",&a);
        k=a;
        while(k!=0){
            sum=sum+(k%10);
            k/=10;
            i++;
        }

    if(a%10==9)printf("%I64d\n",sum);
    else{
        sum=sum+((i-1)*9);
    printf("%I64d\n",sum);
    }
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, a, b, sum=0;
    scanf("%lld", &n);
    if(n&1)
    {
        a = (n+1)/2;
        b = n/2;
    }
    else
    {
        a = n/2 + 1;
        b = n/2- 1;
    }
    while(a)
    {
        sum += a%10;
        a /= 10;
    }
    while(b)
    {
        sum += b%10;
        b /= 10;
    }
    printf("%lld\n", sum);

    return 0;
}

#include <stdio.h>

int Fun(long long n)
{
    int ret = 0;
    while(n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main()
{
    long long n, m;
    scanf("%I64d", &n);
    m = n;
    if(m < 9) {
        printf("%I64d\n", m);
    } else {
        while(m % 10 != 9) {
            --m;
        }
        printf("%d\n", Fun(m) + Fun(n - m));
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

long int deco(long int x){
  long int a = x;
  long int n = 0;
  while(a>=10){
    n+= a%10;
    a /= 10;
  }
  n+=a%10;
  return n;
}

long int pot(long int x, long int y){
  long int a =1;
  for(int c = 0;c<y;c++){
	a *= x;
  }
  return a;
}

int main(){
  long int a;
  scanf("%ld",&a);
  long int p=a;
  long int x,y;
  long int res = 0;
  int n = 0;
  while(p>=10){
    n++;
    p = p/10;
  }
  for(int c = 0;c<n;c++){
	res+= 9*pot(10,c);
  }
  res+= (a/(pot(10,n))-1)*pot(10,n);
  x = deco(res);
  y = deco(a-res);
  printf("%ld",x+y);
}

#include <stdio.h>
#include <stdlib.h>

long long sum(long long a)
{
    long long s =0;
    while(a>0){
    s += a%10;
    a/=10;}
    return (s);
}

int main() {
	//code

	long long n;
	scanf("%lld\n",&n);
	long long tmp1 = n/2, tmp2 = n - (n/2);

	if(tmp1%10==0)
	{
	    tmp1-=1;
	    tmp2+=1;
	}
	if(tmp2%10==0)
	{
	    tmp2-=1;
	    tmp1+=1;
	}

	printf("%lld",sum(tmp1)+sum(tmp2));

	return 0;
}

#include <stdio.h>
#include<stdlib.h>

int main()
{
	__int64 n,sa,sb;
	int s=0;
	scanf("%I64d",&n);
	if(n%2==1)
	{
		sa=n/2;
		sb=sa+1;
	}
	else
	{
		sa=n/2-1;
		sb=n/2+1;
	}
	while(sa)
	{
		s=s+sa%10;
		sa=sa/10;
	}
	while(sb)
	{
		s=s+sb%10;
		sb=sb/10;
	}
	printf("%d",s);
	return 0;
}

#include<stdio.h>
#include<math.h>
int count (long long int n){
	long long int sum=0;
	while(n>0){
		sum+=(n%10);
		n=n/10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d",&n);
	if(n>99){
	long long int t=n,h=0;
	while(t){
		h++;
		t=t/10;
	}
	long long int n1=pow(10,h-1);
	n1-=1;
	long long int j=n-n1;
	j=count(j);
	int f=(9*(h-1));
	printf("%d",f+j);
	return 0;
}
	else{
	long long int l,g;
	l=(n/2)+1;
	g=n-l;
	l=count(l);
	g=count(g);
	printf("%I64d",l+g);
	return 0;

	}
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdint.h"

int main()
{
    char a[12];
      char Char[100];
    int c,d;
    //read first number
    scanf("%s",a);
    //read second number
    c=strlen(a);
   //    digitcounter(a,&result);
   d=0;
   for(int i=0;i<c;i++){
       d+=a[i]-'0';
   }
    printf("%d",d+(c-1)*9);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

long int deco(long int x){
  long int a = x;
  long int n = 0;
  while(a>=10){
    n+= a%10;
    a /= 10;
  }
  n+=a%10;
  return n;
}

long int pot(long int x, long int y){
  long int a =1;
  for(int c = 0;c<y;c++){
	a *= x;
  }
  return a;
}

int main(){
  long int a;
  scanf("%ld",&a);
  long int p=a;
  long int x,y;
  long int res = 0;
  long int n = 0;
  while(p>=10){
    n++;
    p = p/10;
  }
  for(int c = 0;c<n;c++){
	res+= 9*pot(10,c);
  }
  res+= (a/(pot(10,n))-1)*pot(10,n);
  x = deco(res);
  y = deco(a-res);

  if(a>100){
	printf("%ld",n);
	printf("%ld\n",res);
	printf("%ld\n",a-res);
	printf("%ld\n",x);
	printf("%ld\n",y);
  }
  printf("%ld",x+y);
}

#include<stdio.h>
int main()
{
    long long int n=0, n1=0, n2=0, rem=0, temp=0, sum1=0, sum2=0;
    scanf("%I64d", &n);
    if(n%2==0)
    {
        n1 = (n/2)+1;
        n2 = (n-n1);
    }
    else
    {
        n1 = (n/2);
        n2 = (n-n1);
    }
    temp = n1;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    temp = n2;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    printf("%I64d", sum1);
}

#include<stdio.h>
int count (int n){
	int sum=0;
	while(n>0){
		sum+=(n%10);
		n=n/10;
	}
	return sum;
}
int main(){
	long long int n;
	scanf("%I64d",&n);
	long long int l,g;
	l=(n/2)+1;
	g=n-l;
	l=count(l);
	g=count(g);
	printf("%d",l+g);
	return 0;

}

#include <stdio.h>
#include <string.h>
int main()
{
	char s[15];
	int ans, len;
	while (~scanf("%s", s))
	{
		ans = 0;
		len = strlen(s);
		for (int i = 0; i < len; i++)
		{
			if (s[i] - '0')
			{
				if (s[i] != '9')
					ans += s[i] - '0' + (len - i - 1) * 9;
				else ans += s[i] - '0';
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int m;
    scanf("%lld", &m);
    if(m<=18)
    {
        printf("%I64d", m);
        return 0;
    }
    long long int x,y;
    x=m-1-(m%10);
    y=m-x;
    int count=0,j=0;
    while(x)
    {
        count+=x%10;
        x=x/10;
    }
    if(y==10)
        y=1;
    count+=y;
    printf("%d", count);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

int deco(int x){
  int a = x;
  int n=0;
  while(a>=10){
    n+= a%10;
    a = a/10;
  }
  n+=a%10;
  return n;
}

int main(){
  long int a;
  scanf("%ld",&a);
  long int max=0;
  long int x,y;
  long int b,d;
  for(long int c = 1;c<(a/2)+1;c++){
    x = deco(c);
    y = deco(a-c);
    if(x+y > max){
	  max = x+y;
	  b =c;
	  d =a-c;
	}
  }
  printf("%ld %ld\n",b,d);
  printf("%ld",max);
}

#include <stdio.h>
#include <math.h>

#define MAX_LIMIT 10e12

typedef long long LL;

int sum_of_digit(LL x)
{
	int sum = 0;

	while (x != 0)
	{
		sum += x % 10;
		x /= 10;
	}

	return sum;
}

LL get_highest_digit(LL x, LL *a)
{
	LL temp = x;
	*a = 0;
	while (x != 0)
	{
		temp = x;
		x /= 10;
		(*a)++;
	}

	return temp;
}

int main()
{
	//input
	LL n, a, b;
	scanf("%I64d", &n);

	//produce output
	LL digits;
	LL msb = get_highest_digit(n, &digits);

	a = msb * pow(10, digits-1);
	a--;

	b = n - a;

	printf("%d\n", sum_of_digit(a) + sum_of_digit(b));
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int m;
    scanf("%lld", &m);
    if(m<=18)
    {
        printf("%I64d", m);
        return 0;
    }
    long long int x,y;
    long long int p,a;
    int q=0;
    p=m;
    while(p)
    {
        q++;
        p=p/10;
    }
    a=pow(10,q-1);
    x=m-1-(m%a);
    y=m-x;
    int count=0;
    while(x)
    {
        count+=x%10;
        x=x/10;
    }
    while(y)
    {
        count+=y%10;
        y=y/10;
    }
    printf("%d", count);
    return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    long long num,i,j,temp1,temp2;
    scanf("%I64d",&num);
    if(num%2==0)
    {
        temp1=(num/2)-1;
    }
    else
    {
        temp1=num/2;
    }
    temp2=num-temp1;
    char str1[13],str2[13];
    sprintf(str1,"%I64d",temp1);
    sprintf(str2,"%I64d",temp2);
    int length=strlen(str1);
    int sum=0;
    for(i=0;i<strlen(str1);i++)
    {
        sum+=(str1[i]-'0');
    }
    for(i=0;i<strlen(str2);i++)
    {
        sum+=(str2[i]-'0');
    }
    printf("%d",sum);
}

#include <stdio.h>

int digs(long long n) {
	int result = 0;
	while (n > 0) {
		result += n % 10;
		n /= 10;
	}
	return result;
}

int main() {
	long long n;
	scanf("%I64d", &n);

	long long a = 0;
	for (a = 0; a < n; a=a*10+9) ;
	a = a/10;

	printf("%I64d\n", digs(a) + digs(n-a));

	return 0;
}

#include<stdio.h>
int main()
{
    long long int a,i=0,j,k,sum=0;
    scanf("%I64d\n",&a);
    while(a!=0){
        sum=sum+(a%10);
        a/=10;
        i++;
    }
    sum=sum+((i-1)*9);
    printf("%I64d\n",sum);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdint.h"

int main()
{
    char a[12];
      char Char[100];
    int c,d;
    //read first number
    scanf("%s",a);
    //read second number
    c=strlen(a);
   //    digitcounter(a,&result);
   d=0;
   int b=1;
   for(int i=c-1;i>1;i--){
        if((a[i]-'0')==9){
        if(!b){
        d+=(a[i]-'0');

        }
        }else  {
                 d+=(a[i]-'0');
                 b=0;
                 }
          }
          d+=(a[0]-'0');
   if((a[c-1]-'0')<9)  d+=(a[c-1]-'0');
    printf("%d",d+(c-1)*9);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int m;
    scanf("%lld", &m);
    if(m<=18)
    {
        printf("%I64d", m);
        return 0;
    }
    long long int x,y;
    x=m-1-(m%10);
    y=m-x;
    int count=0,j=0;
    while(x)
    {
        count+=x%10;
        x=x/10;
    }
    count+=y;
    printf("%d", count);
    return 0;
}

#include<stdio.h>

int main()
{
    int n,sum,i=0,b;
    scanf("%d",&n);
    int ten =1;
    while(n-ten*10>0)
    {
        i++;
        ten*=10;
    }
    b = n-ten+1;
    sum = 9*i;
    while(b!=0)
    {
        sum += b%10;
        b = b/10;
    }
    printf("%d\n",sum);

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdint.h"

int main()
{
    char a[12];
      char Char[100];
    int c,d;
    //read first number
    scanf("%s",a);
    //read second number
    c=strlen(a);
   //    digitcounter(a,&result);
   d=0;
   for(int i=0;i<c;i++){
       d+=a[i]-'0';
   }
    printf("%d",d+(c-1)*9);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, a=0, b, sum=0, x=0;
    scanf("%lld", &n);
    for(a=0; a<n; )
    {
        a = x*10 + 9;
        x++;
    }
    a -= 10;
    b = n-a;
    while(a)
    {
        sum += a%10;
        a /= 10;
    }
    while(b)
    {
        sum += b%10;
        b /= 10;
    }
    printf("%lld\n", sum);

    return 0;
}

#include<stdio.h>

///#define long long LL
///expected initializer

long long digitSum(long long n)
{
    long long i,j,s=0;
    while(n)
    {
        s=s+n%10;

        n= n/10;
    }

    return s;
}

int main(void)
{
    long long i,j,k,l,l1,n;

    scanf("%lld",&n);

    if(n&1)
    {
        j=n/2;
        k=j+1;
    }
    else
    {
        j=(n/2)-1;
        k=(n/2)+1;
    }
    l=digitSum(j);
    l1=digitSum(k);

    ///printf("%lld %lld\n",l,l1);

    printf("%lld\n",l+l1);

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n;
    long long int div,hold,count=0,sum;
    long long int first,sec;
    long long x=0,y=0,total;

    scanf("%I64d",&n);

    div = n/2;

    hold = div;

        while(hold!=0)
        {
            sum = hold%10;
            hold = hold/10;
            count++;
        }

        if(count==1 || count==0)
        {
            printf("%d",n);
            return 0;
        }
        else if(count==2)
        {
            first = sum*10-1;
            sec = n-first;
        }
        else if(count==3)
        {
            first = sum*100-1;
            sec = n-first;
        }
        else if(count==4)
        {
            first = sum*1000-1;
            sec = n-first;
        }
        else if(count==5)
        {
            first = sum*10000-1;
            sec = n-first;
        }
        else if(count==6)
        {
            first = sum*100000-1;
            sec = n-first;
        }
        else if(count==7)
        {
            first = sum*1000000-1;
            sec = n-first;
        }
        else if(count==8)
        {
            first = sum*10000000-1;
            sec = n-first;
        }
        else if(count==9)
        {
            first = sum*100000000-1;
            sec = n-first;
        }
        else if(count==10)
        {
            first = sum*1000000000-1;
            sec = n-first;
        }
        else if(count==11)
        {
            first = sum*10000000000-1;
            sec = n-first;
        }
        else if(count==12)
        {
            first = sum*100000000000-1;
            sec = n-first;
        }

        while(first!=0)
        {
            x = x + first%10;
            first = first/10;
        }
        while(sec!=0)
        {
            y = y + sec%10;
            sec = sec/10;
        }

            total = x+y;

            printf("%I64d",total);

        return 0;

}

#include <stdio.h>
#include <math.h>
int main() {
	long long n,n2;
	long long ans=0;
	scanf("%I64d", &n);

	if (n < 10) {
		printf("%d", n);
		return 0;
	}
	ans += 10 + n % 10;
	n -= 10 + n % 10;

	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	printf("%d", ans);
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long ll;
typedef long double LD;

#define MAXN 101

#define MIN(a,b) ((a)<(b)?(a):(b))

char arr[MAXN];

int sumdigits(ll input)
{
    int sum;
    sum = 0;
    while (input >0)
    {
        sum += input%10;
        input /= 10;
    }
    return (sum);
}

int main(void)
{
    ll N;
    int ans, nines;
    int temp;

	#ifndef ONLINE_JUDGE
    FILE *fp;
	fp = freopen("..\\..\\1060\\B\\1060B.TXT","r",stdin);
	//fp = freopen("1047C.TXT","r",stdin);
	if (fp == NULL)
    {
        printf ("Cannot open file\n\n");
        exit(0);
    }
	#endif

    #ifndef ONLINE_JUDGE

    #else
        scanf("%I64d",&N);
    #endif

    if (N<9)
    {
        ans = 9;
    }
    else
    {
        nines = 1;
        temp = N;
        while (temp > 10)
        {
            nines *= 10;
            temp /=10;
        }
        nines -=1;

        ans = sumdigits(nines) + sumdigits(N-nines);
    }
    printf ("%d",ans);

    return (0);
}

#include<stdio.h>
int main()
{
	long long int n, i, x=0;
	char s[14];

	scanf("%lld", &n);

	if(n<10)
	{
		printf("%lld", n);
	}
	else
	{
		n=n-9;

		sprintf(s, "%lld", n);

		for(i=0; s[i]!='\0'; i++)
		{
			x+=s[i]-'0';
		}
		printf("%lld", x+9);
	}
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    long long int n=0, n1=0, n2=0, rem=0, temp=0, sum1=0, sum2=0;
    scanf("%I64d", &n);
    n1 = n/2;
    n2 = (n-n1);
    temp = n1;
    while(temp!=0)
    {
        rem = (temp%10);
        sum1 += rem;
        temp = temp/10;
    }
    temp = n2;
    while(temp!=0)
    {
        rem = (temp%10);
        sum2 += rem;
        temp = temp/10;
    }
    printf("%I64d", sum1+sum2);
}

#include <stdio.h>
int main(){
    long long n;
    scanf("%lld",&n);
    long long a=0;long long b=0;
    long long counter=10;int flag=1;
    while(n!=0){
        if(flag==1){
        if(n>9*counter/10)
        a+=9*(counter/10);
        else{
        a+=n%counter;
        break;}
        }
        else{
            if(n>9*counter/10)
            b+=9*(counter/10);
            else{
            b+=n%counter;
        }}
        n-=9*(counter/10);
        if(flag==-1)
            counter*=10;
        flag*=-1;

    }

    int sum=0;
    while(a!=0){
        sum+=a%10;
        a/=10;
    }
    while(b!=0){
        sum+=b%10;
        b/=10;
    }
    printf("%d",sum);
    return 0;
}

#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a=0;int b=0;
    int counter=10;int flag=1;
    while(n!=0){
        if(flag==1){
        if(n>9*counter/10)
        a+=9*(counter/10);
        else{
        a+=n%counter;
        break;}
        }
        else{
            if(n>9*counter/10)
            b+=9*(counter/10);
            else{
            b+=n%counter;
        }}
        n-=9*(counter/10);
        if(flag==-1)
            counter*=10;
        flag*=-1;

    }

    int sum=0;
    while(a!=0){
        sum+=a%10;
        a/=10;
    }
    while(b!=0){
        sum+=b%10;
        b/=10;
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
	long long int n, i, x=0;
	char s[14];

	scanf("%lld", &n);

	if(n<10)
	{
		printf("%lld", n);
	}
	else
	{
		sprintf(s, "%lld", n);

		for(i=0; s[i]!='\0'; i++)
		{
			x+=s[i]-'0';
		}
		printf("%lld", x+((i-1)*9));
	}
	return 0;
}

#include<stdio.h>

int main()
{
    long long int n, p, q,sum=0;

    scanf("%lld", &n);

    if(n%10==9)
    {
        while(n!=0)
        {
            p=n%10;
            sum+=p;
            n=n/10;
        }
    }
    else
    {
        q=n%10;
        q++;
        n=n-q;
        while(n!=0)
        {
            p=n%10;
            sum+=p;
            n=n/10;
        }
        sum+=q;
    }
    printf("%lld\n", sum);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n;
    long long int div,hold,count=0,sum,fal=0;
    long long int first,sec;
    long long x=0,y=0,total;

    scanf("%I64d",&n);

    div = n/2;

    hold = div;

        while(hold!=0)
        {
            fal = fal + hold%10;
            sum = hold%10;
            hold = hold/10;
            count++;
        }

        if(fal/count==9)
        {
            total = 2*fal;
            printf("%I64d",total);
            return 0;
        }

        if(count==1 || count==0)
        {
            printf("%d",n);
            return 0;
        }
        else if(count==2)
        {
            first = sum*10-1;
            sec = n-first;
        }
        else if(count==3)
        {
            first = sum*100-1;
            sec = n-first;
        }
        else if(count==4)
        {
            first = sum*1000-1;
            sec = n-first;
        }
        else if(count==5)
        {
            first = sum*10000-1;
            sec = n-first;
        }
        else if(count==6)
        {
            first = sum*100000-1;
            sec = n-first;
        }
        else if(count==7)
        {
            first = sum*1000000-1;
            sec = n-first;
        }
        else if(count==8)
        {
            first = sum*10000000-1;
            sec = n-first;
        }
        else if(count==9)
        {
            first = sum*100000000-1;
            sec = n-first;
        }
        else if(count==10)
        {
            first = sum*1000000000-1;
            sec = n-first;
        }
        else if(count==11)
        {
            first = sum*10000000000-1;
            sec = n-first;
        }
        else if(count==12)
        {
            first = sum*100000000000-1;
            sec = n-first;
        }

        while(first!=0)
        {
            x = x + first%10;
            first = first/10;
        }
        while(sec!=0)
        {
            y = y + sec%10;
            sec = sec/10;
        }

            total = x+y;

            printf("%I64d",total);

        return 0;

}

#include<stdio.h>
#include<stdlib.h>

long int deco(long int x){
  long int a = x;
  long int n = 0;
  while(a>=10){
    n+= a%10;
    a /= 10;
  }
  n+=a%10;
  return n;
}

long int pot(long int x, long int y){
  long int a =1;
  for(int c = 0;c<y;c++){
	a *= x;
  }
  return a;
}

int main(){
  long int a;
  scanf("%ld",&a);
  long int p=a;
  long int x,y;
  long int res = 0;
  int n = 0;
  while(p>=10){
    n++;
    p = p/10;
  }
  for(int c = 0;c<n;c++){
	res+= 9*pot(10,c);
  }
  res+= (a/(pot(10,n))-1)*pot(10,n);
  x = deco(res);
  y = deco(a-res);
  if(a>100){
	printf("%ld\n",res);
	printf("%ld\n",a-res);
	printf("%ld\n",x);
	printf("%ld\n",y);
  }
  printf("%ld",x+y);
}

#include <stdio.h>
#include <string.h>
int main()
{
	char s[15];
	int ans, len;
	while (~scanf("%s", s))
	{
		ans = 0;
		len = strlen(s);
		ans += s[0] - '0' + (len - 1) * 9;
		for (int i = 1; i < len; i++)
			ans += s[i] - '0';
		printf("%d\n", ans);
	}
	return 0;
}


/* http://catb.org/esr/intercal/ick.htm */
/* find xor of largest and last array elements */
#include <stdio.h>

#define N	10

int main() {
	static int aa[N];
	int n, i, max;

	scanf("%d", &n);
	max = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		if (max < aa[i])
			max = aa[i];
	}
	printf("%d\n", max ^ aa[n - 1]);
	return 0;
}

#include<stdio.h>
int main(){
	int a[10], i, n, max=0;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
		if(max<a[i]) max=a[i];
	}
	printf("%d", max^a[n-1]);
	return 0;
}