#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll dp[19][10000][2][2];
bool ck(int c){
    if(c/1000==5&&c/100%10==1&&c%10==3) return true;
    return false;
}
int main(){
    string s;
    cin>>s;
    int n=s.size();
    dp[0][0][0][0]=1;
    rep(i,n)rep(j,10000)rep(k,2)rep(l,2){
        int ulim=l?9:s[i]-'0';
        rep(p,ulim+1){
            dp[i+1][(j*10+p)%10000][k||ck((j*10+p)%10000)][l||p<ulim]+=dp[i][j][k][l];
        }
    }
    ll ans=0;
    rep(i,10000)rep(k,2) ans+=dp[n][i][1][k];
    cout<<ans<<endl;
    return 0;
}
