#include <bits/stdc++.h>
using namespace std;
int N, ans = 0, cnt[10] = {0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  if (N < 357) {
    ans = 0;
  } else if (N < 375) {
    ans = 1;
  } else if (N < 537) {
    ans = 2;
  } else if (N < 573) {
    ans = 3;
  } else if (N < 735) {
    ans = 4;
  } else if (N < 753) {
    ans = 5;
  } else if (N < 3357) {
    ans = 6;
  } else {
    ans += 6;
    int a = 3357;
    if (N > 99999999) {
      ans += 8333;
      a = 333333356;
      if (N > 399999999) {
        ans = 14389;
        a = 4333333333;
      }
    }
    while (true) {
      bool s = false, t = false, f = false, ok = true;
      a++;
      int tmp = a, digit = 0;
      while (tmp) {
        cnt[digit] = tmp % 10;
        tmp /= 10;
        digit++;
      }
      int sum;
      for (int i = (0); i < (digit); ++i) {
        if (cnt[i] == 3) t = true;
        if (cnt[i] == 5) f = true;
        if (cnt[i] == 7) s = true;
        if (cnt[i] != 3 && cnt[i] != 5 && cnt[i] != 7) {
          ok = false;
        }
      }
      if (N < a) {
        break;
      }
      if (t && f && s && ok) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
