#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const long long INF = 5e18;
signed main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int dp[11][2][2][2][2][2] = {};
  dp[0][0][0][0][0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) {
          for (int m = 0; m < 2; m++) {
            for (int o = 0; o < 2; o++) {
              int lim = j ? 9 : s[i] - '0';
              for (int p = 0; p <= lim; p++) {
                dp[i + 1][j || p < lim][k || p == 7][l || p == 5][m || p == 3]
                  [o || (p != 7 && p != 5 && p != 3)] += dp[i][j][k][l][m][o];
              }
            }
          }
        }
      }
    }
  }
  cout << dp[s.size()][0][1][1][1][0] + dp[s.size()][1][1][1][1][0] << endl;
}
