#include <bits/stdc++.h>
using namespace std;
const int A = 18;
long long p10[A];
long long dp[A + 1][2][6];
int dig[A];
int nxt[6][10];
int main() {
  for (int i = 0; i < (int)(A); ++i) {
    if (i == 0)
      p10[i] = 1;
    else
      p10[i] = 10 * p10[i - 1];
  }
  long long n;
  cin >> n;
  for (int i = 0; i < (int)(A); ++i) {
    dig[i] = n % 10;
    n /= 10;
  }
  dp[A][1][0] = 1;
  nxt[0][5] = 1;
  nxt[1][1] = 2;
  nxt[1][5] = 1;
  for (int i = 0; i < (int)(10); ++i) nxt[2][i] = 3;
  nxt[2][5] = 4;
  nxt[3][3] = 5;
  nxt[3][5] = 1;
  nxt[4][1] = 2;
  nxt[4][3] = 5;
  nxt[4][5] = 1;
  for (int i = 0; i < (int)(10); ++i) nxt[5][i] = 5;
  for (int i = A - 1; i >= 0; --i) {
    for (int j = 0; j < (int)(10); ++j) {
      for (int k = 0; k < (int)(6); ++k) {
        dp[i][0][nxt[k][j]] += dp[i + 1][0][k];
      }
    }
    for (int j = 0; j < (int)(dig[i]); ++j) {
      for (int k = 0; k < (int)(6); ++k) {
        dp[i][0][nxt[k][j]] += dp[i + 1][1][k];
      }
    }
    for (int k = 0; k < (int)(6); ++k)
      dp[i][1][nxt[k][dig[i]]] += dp[i + 1][1][k];
    if (0) {
      for (int j = 0; j < (int)(2); ++j) {
        for (int k = 0; k < (int)(6); ++k) cerr << " " << dp[i][j][k];
        cerr << "|";
      }
      cerr << endl;
    }
  }
  cout << dp[0][0][5] + dp[0][1][5] << endl;
}
