#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int64 dp[20][4][2][2][10];
string S;
int64 rec(int idx, int match, bool matched, bool lim, int pv) {
  if (idx == S.size()) return matched;
  if (~dp[idx][match][matched][lim][pv])
    return dp[idx][match][matched][lim][pv];
  int64 ret = 0;
  for (int i = lim ? S[idx] - '0' : 9; i >= 0; i--) {
    bool next_lim = lim & (S[idx] - '0' == i);
    if (matched) {
      ret += rec(idx + 1, match, matched, next_lim, 0);
    } else if (match == 0 && i == 5) {
      ret += rec(idx + 1, 1, matched, next_lim, i);
    } else if (match == 1 && i == 1) {
      ret += rec(idx + 1, 2, matched, next_lim, i);
    } else if (match == 2) {
      ret += rec(idx + 1, 3, matched, next_lim, i);
    } else if (match == 3) {
      if (i == 3)
        ret += rec(idx + 1, 0, true, next_lim, i);
      else if (pv == 5 && i == 1)
        ret += rec(idx + 1, 2, matched, next_lim, i);
      else
        ret += rec(idx + 1, i == 5, matched, next_lim, i);
    }
  }
  return dp[idx][match][matched][lim][pv] = ret;
}
int main() {
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0, 0, true, 0) << endl;
}
