#include <bits/stdc++.h>
using namespace std;
void push_s(int i);
int a = 0, b = 0, c = 0;
int s = 0;
int main() {
  string ns;
  cin >> ns;
  int size = ns.size();
  int n = stoi(ns);
  int cnt = 0;
  for (int i = 0; i < (int)(5); i++) {
    push_s(i);
    for (int j = 0; j < (int)(5); j++) {
      push_s(j);
      for (int k = 0; k < (int)(5); k++) {
        push_s(k);
        for (int l = 0; l < (int)(5); l++) {
          push_s(l);
          for (int m = 0; m < (int)(5); m++) {
            push_s(m);
            for (int r = 0; r < (int)(5); r++) {
              push_s(r);
              for (int y = 0; y < (int)(5); y++) {
                push_s(y);
                for (int t = 0; t < (int)(5); t++) {
                  push_s(t);
                  for (int x = 0; x < (int)(5); x++) {
                    push_s(x);
                    if (s <= n && a > 0 && b > 0 && c > 0) cnt++;
                    s = 0;
                    a = 0;
                    b = 0;
                    c = 0;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << cnt << endl;
}
void push_s(int i) {
  if (i == 0) {
    a++;
    s += 3 * pow(10, a + b + c - 1);
  } else if (i == 1) {
    b++;
    s += 5 * pow(10, a + b + c - 1);
  } else if (i == 2) {
    c++;
    s += 7 * pow(10, a + b + c - 1);
  }
}
