#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N;
  int dp[12][2][2][2][2];
  for (int i = 0; i < 12; i++) {
    for (int k = 0; k < 2; k++) {
      for (int l = 0; l < 2; l++) {
        for (int m = 0; m < 2; m++) {
          for (int n = 0; n < 2; n++) {
            dp[i][k][l][m][n] = 0;
          }
        }
      }
    }
  }
  dp[0][0][0][0][0] = 1;
  for (int i = 1; i < N.size() - 2; i++) {
    dp[i][1][0][0][0] = 1;
  }
  for (int i = 0; i < N.size(); i++) {
    for (int smaller = 0; smaller < 2; smaller++) {
      for (int three = 0; three < 2; three++) {
        for (int five = 0; five < 2; five++) {
          for (int seven = 0; seven < 2; seven++) {
            for (int x = 0; x < (smaller ? 10 : (N[i] - '0') + 1); x++) {
              if (x != 3 && x != 5 && x != 7) continue;
              dp[i + 1][smaller || x < (N[i] - '0')][three || x == 3]
                [five || x == 5][seven || x == 7] +=
                  dp[i][smaller][three][five][seven];
            }
          }
        }
      }
    }
  }
  cout << dp[N.size()][0][1][1][1] + dp[N.size()][1][1][1][1] << endl;
  return 0;
}
