#include <bits/stdc++.h>
using namespace std;
long long N;
map<string, long long> M;
vector<char> P{'3', '5', '7'};
long long func(string S) {
  long long K = stoll(S);
  if (K > N) return 0;
  long long ret = 0;
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    string X = S + P[i];
    if (M.count(X))
      ret += M[X];
    else
      ret += func(X);
  }
  set<char> X;
  for (long long i = (long long)(0); i < (long long)(S.size()); i++)
    X.insert(S[i]);
  if (X.size() == 3) ret++;
  return M[S] = ret;
}
signed main() {
  cin >> N;
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(3); i++) {
    string X;
    X += P[i];
    ans += func(X);
  }
  cout << ans << endl;
}
