#include <bits/stdc++.h> using namespace std; const int N = 10; int dp[N][5][2]; int l, num[N]; int dat[4] = {2, 0, 1, 8}; int dfs(int pos, int pn, int lim) { if(pos == -1) { if(pn == 4) return 1; return 0; } if(dp[pos][pn][lim] != -1 && (!lim)) return dp[pos][pn][lim]; int top = lim ? num[pos] : 9; int rtn = 0; for(int i = 0; i <= top; ++ i) { int npn = 4; if(pn < 4) { if(dat[pn] == i) npn = pn + 1; else npn = pn; } rtn += dfs(pos - 1, npn, lim&&(i==top)); } if(!lim) dp[pos][pn][lim] = rtn; return rtn; } int main() { int x; scanf("%d", &x); memset(dp, -1, sizeof(dp)); l = 0; while(x) { num[l ++] = x % 10; x /= 10; } printf("%d ", dfs(l - 1, 0, 1)); }