#include <bits/stdc++.h>
using namespace std;
int n;
int bj[4];
int dfs(int now) {
  if (now > n) return 0;
  int temp = 10 * now;
  int ans = 0;
  if (bj[1] && bj[2] && bj[3]) ans++;
  bj[1]++;
  ans += dfs(temp + 3);
  bj[1]--;
  bj[2]++;
  ans += dfs(temp + 5);
  bj[2]--;
  bj[3]++;
  ans += dfs(temp + 7);
  bj[3]--;
  return ans;
}
int main() {
  scanf("%d", &n);
  printf("%d", dfs(0));
  return 0;
}
