#include<iostream>
using namespace std;

bool check(int i) {
    int temp1 = i, temp2 = i * i;
    while (temp1) { //验证后几位
        if (temp2 % 10 != temp1 % 10) break;
        temp1 /= 10;
        temp2 /= 10;
    }
    return temp1 == 0;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int i = 1;
    while(i <= n){
        if(check(i)) ++ans;
        i += 4;
        if(i>n)
            break;
        if(check(i)) ++ans;
        i += 1;
        if(i>n)
            break;
        if(check(i)) ++ans;
        i += 5;
    }

    cout << ans+1 << endl;
    return 0;
}