using namespace std;
#include<algorithm>
#include<cmath>
//判断是否为自守数
bool func(int n)
{
    int l=0;
    //l是位数,此处pow一定要取整,pow默认是浮点型运算
    while(n/(int)pow(10,l)!=0)
    {
        l++;
    }
    l=(int)pow(10,l);
    //判断是否为自守数:平方减去自身,对10^l取余为0
    if((n*n-n)%l==0)
    {
           return true;
    }
    else
    {
        return false;
    }
        
    
    
    
    
    
}


int main()
{
    int count,n;
    while(cin>>n)
    {
        count=0;
        for(int i=0;i<=n;i++)
        {
            if(func(i)==true)
            {
                count++;
            }
        }
        
        cout<<count<<endl;
        
        
        
    }
    
    
    return 0;
}