#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i, b) for (int i = 0; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define vt vector
#define all(v) v.begin(), v.end()
const ll M = 998244353;
using namespace std;
ll num(string t)
{
    ll r = 0;
    for (ll i = 0; i < t.length(); i++)
    {
        r = r * 10 + (t[i] - '0');
    }
    return r;
}
ll modularExponentiation(ll x, ll n, ll M)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0)
        return modularExponentiation((x * x) % M, n / 2, M);
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
ll binaryExponentiation(ll x, ll n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0)
        return binaryExponentiation(x * x, n / 2);
    else
        return x * binaryExponentiation(x * x, (n - 1) / 2);
}
ll GCD(ll A, ll B)
{
    if (B == 0)
        return A;
    else
        return GCD(B, A % B);
}
ll extended_GCD(ll a, ll b, ll &x, ll &y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = extended_GCD(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}
ll modinv(ll a, ll mod)
{
    ll x, y;
    extended_GCD(a, mod, x, y);
    if (x < 0)
        x += mod;
    return x;
}
ll modPrimeInverse(ll A, ll M)
{
    return modularExponentiation(A, M - 2, M);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vt<string> v;
    ll val = 6;
    vt<ll> v2;
    ll flag=0;
    while (val--)
    {
        // cout<<v[v.size()-1]<<"\n";
        // if (v.size()!=0&&v[v.size() - 1] >= "999999")
        //     break;
        vt<string> v1;
        if (v.size() == 0)
        {
            for (int i = 0; i <= 9; i++)
            {
                string ans = "";
                ans += to_string(i);
                v.push_back(ans);
                ans += to_string(i);
                if(ans!="00")
                    v2.push_back(num(ans));

                // cout << ans << "\n";
            }
        }
        else
        {
            for (int i = 0; i < v.size(); i++)
            {

                for (int j = 0; j <= 9; j++)
                {
                    string ans = "";
                    ans += to_string(j);
                    ans += v[i];
                    v1.push_back(ans);
                    // cout<<ans<<"     ";
                    ans += ans;
                    ll x=num(ans);
                    if(ans[0]!='0')
                        v2.push_back(x);
                    // cout << ans << "\n";
                    if(ans=="999999999999")
                    {
                        flag=1;
                        break;
                    }
                }
                if(flag)break;
            }
            if(flag)break;
            v=v1;
        }
      
    }
    sort(all(v2));
    // if(s.find(n); != s.end()){
    //     cout<<*(s.find(n));
    // }
    if (binary_search(v2.begin(), v2.end(), n))
    {
        // cout << n << "\n";
        cout << lower_bound(v2.begin(), v2.end(), n) - v2.begin() + 1 << "\n";
    }
    else
    {
        if (n < 11)
        {
            cout << "0";
        }
        else
        {
            cout << lower_bound(v2.begin(), v2.end(), n) - v2.begin() << "\n";
        }
    }

    // f(i, v2.size()) cout << v2[i] << "\n";
#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
#endif
    return 0;
}
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  unsigned long long N ;
  unsigned long long ans=0;
  unsigned long long V[100];
  int i=1;
 
 
  cin>>N;
  unsigned long long M=N;
  
while(M>0){
  V[i]=M%10;
  M=M/10;
  i++;
}
 
  if(0<N && N<11){
    ans=ans;
 
  }
 
  else if(11<=N && N<=99){
    int A=V[2];
    int B=V[1];
    if(A<=B){
      ans = A;
    }
    else{
      ans =A-1;
    }
  }
 
  else if(99<N && N <1010){
    ans =9;
 
  }
 
  else if(1010<=N && N<=9999){
    int A=V[4]*10+V[3];
    int B=V[2]*10+V[1];
    if(A<=B){
      ans=A;
    }
    else{
      ans=A-1;
    }
  }
 
  else if(9999<N && N <100100){
    ans = ans+99;
 
  }
  
  else if(100100<=N && N<=999999){
    int A=V[6]*100+V[5]*10+V[4];
    int B=V[3]*100+V[2]*10+V[1];
    if(A<=B){
      ans=A;
    }
    else{
      ans=A-1;
    }
  }
 
  else if(999999<N && N <10001000){
    ans = ans+999;
 
  }
 
  else if(10001000<=N && N<=99999999){
    int A=V[8]*1000+V[7]*100+V[6]*10+V[5];
    int B=V[4]*1000+V[3]*100+V[2]*10+V[1];
    if(A<=B){
      ans=A;
    }
    else{
      ans=A-1;
    }
  }
 
    else if(99999999<N && N <1000010000){
    ans = ans+9999;
 
  } 
 
  else if(1000010000<=N && N<=9999999999){
    unsigned long long A=V[10]*10000+V[9]*1000+V[8]*100+V[7]*10+V[6];
    unsigned long long B=V[ 5]*10000+V[4]*1000+V[3]*100+V[2]*10+V[1];
    if(A<=B){
      ans=A;
    }
    else{
      ans=A-1;
    }
  }
  else if(9999999999<N && N<100000100000){
    ans = ans + 99999;
  }
  else if(100000100000<=N && N<=999999999999){
    unsigned long long A=V[12]*100000+V[11]*10000+V[10]*1000+V[9]*100+V[8]*10+V[7];
    unsigned long long B=V[ 6]*100000+V[ 5]*10000+V[ 4]*1000+V[3]*100+V[2]*10+V[1];
    if(A<=B){
      ans=A;
    }
    else{
      ans=A-1;
    }
  }
  else if(999999999999<N && N<10000001000000){
    ans = ans + 999999;    
 
  }
 
    cout<< ans <<endl;

}