#include <bits/stdc++.h>
using namespace std;
long long dp[20][2][10][10][10];
string num;
long long Stoll(string s) {
  long long res = 0;
  for (long long i = 0; i < s.size(); i++) res = res * 10 + s[i] - '0';
  return res;
}
long long dfs(long long x, long long y, long long p3, long long p2,
              long long p1) {
  if (num.size() <= x) return 0;
  if (dp[x][y][p3][p2][p1] != -1) return dp[x][y][p3][p2][p1];
  long long res = 0;
  if (y == 0) {
    long long p = num[x] - '0';
    if (p3 == 5 && p2 == 1 && p == 3) {
      if (x != num.size() - 1) res += Stoll(num.substr(x + 1));
      res++;
    } else
      res += dfs(x + 1, 0, p2, p1, p);
    for (long long i = 0; i < num[x] - '0'; i++) {
      if (p3 == 5 && p2 == 1 && i == 3) {
        if (x != num.size() - 1) res += Stoll(num.substr(x + 1));
        res++;
      } else
        res += dfs(x + 1, 1, p2, p1, i);
    }
  }
  if (y == 1) {
    for (long long i = 0; i < 10; i++) {
      if (p3 == 5 && p2 == 1 && i == 3) {
        long long X = 1;
        for (long long j = 0; j < num.size() - x - 1; j++) X *= 10;
        res += X;
      } else
        res += dfs(x + 1, 1, p2, p1, i);
    }
  }
  return dp[x][y][p3][p2][p1] = res;
}
signed main() {
  cin >> num;
  memset(dp, -1, sizeof(dp));
  cout << dfs(0, 0, 0, 0, 0) << endl;
  return 0;
}
