#include <bits/stdc++.h>
using namespace std;
int pow_i(int a, int b) {
  int c = 1;
  for (int i = 0; i < b; ++i) {
    c *= a;
  }
  return c;
}
bool is_753(int n) {
  bool flag_3 = false;
  bool flag_5 = false;
  bool flag_7 = false;
  for (int i = int(log10(n)) + 1; i > 0; --i) {
    int top = n / pow_i(10, i - 1);
    n -= top * pow_i(10, i - 1);
    if (top == 3) {
      flag_3 = true;
    } else if (top == 5) {
      flag_5 = true;
    } else if (top == 7) {
      flag_7 = true;
    }
    if (flag_3 and flag_5 and flag_7) return true;
  }
  return false;
}
vector<int> nums;
void make(int num, int count, int max) {
  if (num > max) {
    return;
  } else {
    if (is_753(num)) {
      nums.push_back(num);
    }
  }
  int a, b, c;
  a = num + 3 * pow_i(10, count);
  b = num + 5 * pow_i(10, count);
  c = num + 7 * pow_i(10, count);
  count++;
  make(a, count, max);
  make(b, count, max);
  make(c, count, max);
}
int main() {
  int n;
  cin >> n;
  make(0, 0, n);
  cout << nums.size() << endl;
  return 0;
}
