#include<bits/stdc++.h>
using namespace std;
/*
int temp[1000],ccc=0;
void mergesort(int a[],int lo,int hi)
{
    if(lo>=hi)return ;
    int mid=(lo+hi)>>1;
    mergesort(a,lo,mid);
    mergesort(a,mid+1,hi);
    int i,j,k;
    for(i=lo,j=mid+1,k=lo;k<=hi;k++)
    {
        if(i==(mid+1))temp[k]=a[j++];
        else if(j==(hi+1))temp[k]=a[i++],ccc+=j-mid-1;
        else if(a[i]<=a[j])temp[k]=a[i++],ccc=ccc+j-mid-1;
        else temp[k]=a[j++];
    }
    for(k=lo;k<=hi;k++)a[k]=temp[k];
}

ll bigmod(ll x,ll y,ll m)
{
    if(y==0)return 1;
    ll n=bigmod(x,y/2,m);
    n=(n*n)%m;
    if(y & 1)n=((n%m)*(x%m))%m;
    return n;
}
ll b[100005],sz;
bool p[1000005];

void seive()
{
    p[0]=p[1]=1;
    b[sz++]=2;
    for(ll i=4;i<=1000000;i+=2)
        p[i]=1;
    for(ll i=3;i<=1000;i+=2)
    {
        if(p[i]==0)
        {
            for(ll j=i*i;j<=1000000;j=j+(i<<1))
            {
                p[j]=1;
            }
        }
    }
    for(ll i=3;i<=1000000;i+=2)if(!p[i])b[sz++]=i;
}
ll cc,a[100005];
void segment(ll x,ll y)
{
    if(x<=2 && 2<=y)cc=1;
    if(y<3)return ;
    if(x<3)x=3;
    if((x&1)==0)x++;
    for(ll i=0;((b[i]*b[i])<=y && i< sz);i++)
    {
        ll j=((x+b[i]-1)/b[i])*b[i];
        if((j&1)==0)j=j+b[i];
        for(;j<=y;j+=(b[i]<<1))
        {
            if(j!=b[i])a[j-x]=1;
        }
    }
    for(int i=0;i<=(y-x);i+=2)
    {
        if(!a[i])cc++;
        a[i]=0;
    }
}

ll diiv(ll x)
{
    ll z=1,m=sqrt(x);
    for(ll i=0;i<sz && b[i]<=m;i++)
    {
        ll c=0;
        while(x%b[i]==0)
        {
            c++;
            x=x/b[i];
        }
        if(c>0)
        {
            z=z*(c+1);
            m=sqrt(x);
        }
    }
    if(x>1)
    {
        z=z<<1;
    }
    return z;
}

void allpossiblerectangle()
{
    int i,j,k,l,x,y,r,c;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {

            for(k=i;k<=r;k++)
            {
                for(l=j;l<=c;l++)
                {
                    for(x=i;x<=k;x++)
                    {
                        for(y=j;y<=l;y++)
                        {
                            //cout<<a[x][y]<<" ";
                        }
                        endll;
                    }
                    endll;
                }
            }
        }
    }
}

vector< int>v[301];priority_queue<pair< int, int> > pq;
int adjm[305][305],dist[305],n,ans,lvl[305],visited[305];
int dijkstra(int k)
{
    int i,j;
    for(i=0;i<=n;i++)
    {
        dist[i]=INT_MAX;
        lvl[i]=INT_MAX;
        visited[i]=0;
    }
    dist[k]=0,lvl[k]=0;
    pq.push(make_pair(0,k));//pair first one = cost(weight) and 2nd one = index ;
    while(pq.empty()==0)
    {
        pair< int, int> a;
        a=pq.top();
        pq.pop();
        int u=v[a.second].size();
        if(visited[a.second]==0)
        {
            visited[a.second]=1;
            //cout<<"MIN  "<<a.second<<endl;
            if(dist[a.second]==LONG_LONG_MAX)continue;
            for(k=0;k<u;k++)
            {
                ll j=v[a.second][k];
                if(dist[a.second]+adjm[a.second][j]<dist[j])
                {
                    //cout<<j<<" "<<adjm[a.second][j]<<endl;
                    dist[j]=dist[a.second]+adjm[a.second][j];
                    lvl[j]=lvl[a.second]+1;
                    pq.push(make_pair(-dist[j],j));
                }
               // else if(adjm[a.second][j]>0 && dist[a.second]+adjm[a.second][j]==dist[j])
                {
                   // lvl[j]=min(lvl[a.second]+1,lvl[j]);
                }
            }
        }
    }
}


int stri(string s)
{
    int i=0,c=0,n=s.size();while(i<n)c=c*10+(s[i]-48),i++;return c;
}
ll strll(string s)
{
    ll i=0,c=0,n=s.size();while(i<n)c=c*10+(s[i]-48),i++;return c;
}
ll number(ll z)
{
    ll m=0,base=10,k=1,c;while(z>0)c=z%base,z/=base,m=(m+c*k),k*=10;return m;
}
*/
#define read() 	        freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n) 	        scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sff(n,m) 	    scanf("%d%d",&n,&m)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n) 	        scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sffl(n,m) 	    scanf("%lld%lld",&n,&m)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps 	        1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define unique(a)      a.erase(unique(a.begin(), a.end()), a.end());
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define var int i,j,k,m,t,x,y,l,r,mid,n,c=0,z=0;
int main()
{
    ll var;
    cin>>n;
    z=0,c=0;
    x=n;k=0;
    while(n)
    {
        n/=10;
        c++;
        k=k*10LL+9LL;
        z+=9LL;
    }
    z-=9LL;
    //cout<<k<<endl;
    k=k/10;
    c--;
    m=1;
    for(i=0;i<c;i++)
    {
        m*=10LL;
    }
    i=1;
    while(i<=9)
    {
        y=(i*m)+k;
        if(y>x)
        {
            break;
        }
        i++;
    }
    z=z+i-1;
    if(x<=9)
    {
        cout<<x<<endl;
        return 0;
    }
    cout<<z<<endl;
}


Measured memory_bytes: 256