#include <bits/stdc++.h>
using namespace std;
const int MxN = 200001;
const int MOD = 1e9 + 7;
int n;
int ans;
inline bool check(int x) {
  int a = 0, b = 0, c = 0;
  while (x) {
    int r = x % 10;
    if (r == 3)
      a++;
    else if (r == 5)
      b++;
    else if (r == 7)
      c++;
    x /= 10;
  }
  if (a > 0 && b > 0 && c > 0)
    return true;
  else
    return false;
}
void dfs(int v) {
  if (v > n) return;
  if (check(v)) ans++;
  dfs(v * 10 + 3);
  dfs(v * 10 + 5);
  dfs(v * 10 + 7);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  dfs(0);
  cout << ans;
  return 0;
}
