#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  if (n < 3357) {
    for (int i = 3357; i <= n; i += 2) {
      int tmp = i, three = 0, five = 0, seven = 0;
      bool x = false;
      while (tmp > 0) {
        if (tmp % 10 == 7) {
          seven++;
        } else if (tmp % 10 == 5) {
          five++;
        } else if (tmp % 10 == 3) {
          three++;
        } else {
          x = true;
          break;
        }
        tmp /= 10;
      }
      if (x) {
        continue;
      }
      if (seven > 0 && five > 0 && three > 0) {
        cnt++;
      }
    }
  } else {
    cnt = 6;
    for (int i = 3357; i <= n; i += 2) {
      int tmp = i, three = 0, five = 0, seven = 0;
      bool x = false;
      while (tmp > 0) {
        if (tmp % 10 == 7) {
          seven++;
        } else if (tmp % 10 == 5) {
          five++;
        } else if (tmp % 10 == 3) {
          three++;
        } else {
          x = true;
          break;
        }
        tmp /= 10;
      }
      if (x) {
        continue;
      }
      if (seven > 0 && five > 0 && three > 0) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
