# include <iostream>
# include <vector>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long t;
    char p;
    t=0;
    p='0';
    long long k;
    k=0;
    vector<char>v;
    for(int i=s.size()-2; i>0; i--)
    {
        if(s[i]==s[i-1] && s[i]!=s[i+1])
        {
            if(s[i]==p)
            {
                int h;
                h=s.size()-(i+1)-(k+2);
                t=t+max(h,0);
                k=s.size()-(i+1);
            }
            else
            {
                t=t+s.size()-(i+1);
                k=s.size()-(i+1);
                p=s[i];
            }
            v.push_back(s[i]);
        }
    }
    char l;
    int r;
    l='0';
    long long w=v.size();
    r=0;
    int g;
    for(int i=0; i<s.size()-2; i++)
    {
        if(s[i]==s[i+1] && s[i]!=s[i+2])
        {
            l=v[v.size()-1];
            v.pop_back();
            i=i+1;
            g=i;
        }
        else
        {
            if(s[i]==l)
            {
               r=r+1;
            }
        }
    }
    if(g!=s.size()-2)
    {
    if(s[s.size()-1]==l)
    {
        r=r+1;
    }
    if(s[s.size()-2]==l)
    {
        r=r+1;
    }
    }
  //  cout<<r<<endl;
  long long z;
  z=t-r;
    cout<<z;
}
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long int
#define f first
#define s second
using namespace  std;
ll mod=1e9+7;
int decimal(int x)
{
    int f=0;
    while(x){if(x%10==7)f=1;x/=10;}
    return f;
}
int octal(int x)
{
    vector<int>oc;
    while(x){oc.pb(x%8);x/=8;}
    int f=0;
    for(auto i:oc)if(i==7)f=1;
    return f;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(decimal(i)||octal(i))ans++;
    }
    cout<<n-ans<<endl;
    return 0;
}
