#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 3000
#define row 1001
#define col 1001
#define N  8
/*
自守数是指一个数的平方的尾数等于该数自身的自然数。例如:25^2 = 625,76^2 = 5776,9376^2 = 87909376。请求出n以内的自守数的个数
接口说明
/*
功能: 求出n以内的自守数的个数
输入参数:
int n
返回值:
n以内自守数的数量。
*/
int CalcAutomorphicNumbers(int n)
{
   //在这里实现功能
   int sum = 0;
   long j, k;
   for (int i = 0; i <= n; i++)
   {
      k = i * i;
      j = i;
      while (j != 0)
      {
         if (j % 10 != k % 10)
         {
            break;
         }
         j /= 10;
         k /= 10;
      }
      if (j == 0)
      {
         sum++;
      }
   }
   return sum;
}
int main()
{
   char s[max];
   char d[max];
   char ss[N][col];
   int seq[N];
   int cnt[N];
   int i = 0, j = 0, k = 0, m = 0, n = 0;
   char a, b, c;
   int  x = 0, y = 0, z = 0;
   while (scanf("%d", &x) != EOF)
   {
      printf("%d\n", CalcAutomorphicNumbers(x));
   }
   return 0;
}