#include <bits/stdc++.h>
using namespace std;
int pow(int n) {
  if (n == 0)
    return 1;
  else
    return pow(n - 1) * 10;
}
int pow3(int n) {
  if (n == 0)
    return 1;
  else
    return pow(n - 1) * 3;
}
int decode(int code) {
  if (code == 0) return 3;
  if (code == 1) return 5;
  if (code == 2) return 7;
  return (code % 3) * 2 + 3 + decode(code / 3) * 10;
}
int _isSft(int value, int seven, int five, int three) {
  if (value == 0) {
    return seven && five && three;
  }
  int tail = value % 10;
  int head = value / 10;
  if (tail == 7) return _isSft(head, 1, five, three);
  if (tail == 5)
    return _isSft(head, seven, 1, three);
  else
    return _isSft(head, seven, five, 1);
}
int isSft(int value) { return _isSft(value, 0, 0, 0); }
int getRank(int N) {
  if (N == 0)
    return 0;
  else
    return getRank(N / 10) + 1;
}
int head(int N) {
  if (N < 10)
    return N;
  else
    return head(N / 10);
}
int tail(int N) { return N % pow(getRank(N) - 1); }
int get(int getRank, int N) { return (N / pow(getRank)) % 10; }
vector<vector<vector<vector<int>>>> memo = vector<vector<vector<vector<int>>>>(
    10,
    vector<vector<vector<int>>>(2, vector<vector<int>>(2, vector<int>(2, 0))));
int solve(int order, int seven, int five, int three) {
  if (memo[order][seven][five][three] != 0)
    return memo[order][seven][five][three];
  if (order == 0)
    return seven && five && three ? 1 : 0;
  else
    return memo[order][seven][five][three] = solve(order - 1, 1, five, three) +
                                             solve(order - 1, seven, 1, three) +
                                             solve(order - 1, seven, five, 1);
}
int solve(int order, int N, int seven, int five, int three) {
  if (order == 0)
    return seven && five && three ? 1 : 0;
  else {
    int headN = head(N);
    int tailN = tail(N);
    if (headN >= 8)
      return solve(order - 1, 1, five, three) +
             solve(order - 1, seven, 1, three) +
             solve(order - 1, seven, five, 1);
    if (headN == 7)
      return solve(order - 1, tailN, 1, five, three) +
             solve(order - 1, seven, 1, three) +
             solve(order - 1, seven, five, 1);
    if (headN == 6)
      return solve(order - 1, seven, 1, three) +
             solve(order - 1, seven, five, 1);
    if (headN == 5)
      return solve(order - 1, tailN, seven, 1, three) +
             solve(order - 1, seven, five, 1);
    if (headN == 4) return solve(order - 1, seven, five, 1);
    if (headN == 3)
      return solve(order - 1, tailN, seven, five, 1);
    else
      return 0;
  }
}
int main() {
  int N;
  cin >> N;
  int NnogetRank = getRank(N);
  int sum = 0;
  for (int i = 1; i <= NnogetRank; i++) {
    sum += solve(i, N, 0, 0, 0);
  }
  cout << sum << endl;
}
