#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int n;

bool isfind(string s, string pat){
    if(s.find(pat) != string::npos) return true;
    else return false;
}

int dfs(int i, string s){
  if(i==10){
    if(isfind(s,"3") && isfind(s,"5") && isfind(s,"7") && stroll(s) <= n) return 1;
    else return 0;
  }
  
  int ans = 0;
  
  if(s.back() == "0") ans+= dfs(i+1,s+"0");
  
  ans += dfs(i+1,s+"3");
  ans += dfs(i+1,s+"5");
  ans += dfs(i+1,s+"7");
  
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cout << dfs(0,"0") << endl;
}