#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  Int dp[20][4][2][2][10];
  memset(dp,-1,sizeof(dp));
  function<Int(Int,Int,Int,Int,Int)> dfs=
    [&](Int pos,Int st,Int ok,Int lim,Int pre){
    if(pos==n) return ok;
    Int &res=dp[pos][st][ok][lim][pre];
    if(~res) return res;
    res=0;
    for(Int i=0;i<=(lim?s[pos]-'0':9);i++){
      Int nlim=lim&&(i==s[pos]-'0');
      if(st==0&&i==5){
	res+=dfs(pos+1,1,ok,nlim,i);
      }else if(st==1&&i==1){
	res+=dfs(pos+1,2,ok,nlim,i);
      }else if(st==2){
	res+=dfs(pos+1,3,ok,nlim,i);
      }else if(st==3){
	if(i==3) res+=dfs(pos+1,0,1,nlim,i);
	else if(pre==5&&i==1) res+=dfs(pos+1,2,ok,nlim,i);
	else res+=dfs(pos+1,i==5,ok,nlim,i);
      }else res+=dfs(pos+1,i==5,ok,nlim,i);
    }
    //cout<<pos<<" "<<st<<" "<<ok<<" "<<lim<<" "<<pre<<":"<<res<<endl;
    return res;
  };
  cout<<dfs(0,0,0,1,0)<<endl;
  return 0;
}

