#include <bits/stdc++.h>
using namespace std;
int count(int x) {
  if (x < 10) {
    return 1;
  } else {
    return 1 + count(x / 10);
  }
}
bool valid(int x) {
  int cnt = count(x);
  bool r[3];
  int end;
  for (int i = 0; i < 3; i++) {
    r[i] = false;
  }
  for (int i = 0; i < cnt; i++) {
    end = x % 10;
    if (end == 3) {
      r[0] = true;
    } else if (end == 5) {
      r[1] = true;
    } else if (end == 7) {
      r[2] = true;
    } else {
      return false;
    }
    x = x / 10;
  }
  for (int i = 0; i < 3; i++) {
    if (r[i] == false) {
      return false;
    } else {
      return true;
    }
  }
}
int dfs(int x, int N) {
  int ret = 0;
  if (x > N) {
    return 0;
  }
  if (valid(x)) {
    ret += 1;
  }
  ret += dfs(10 * x + 3, N) + dfs(10 * x + 5, N) + dfs(10 * x + 7, N);
  return ret;
}
int main() {
  int n;
  cin >> n;
  cout << dfs(0, n) << endl;
  return 0;
}
