#include <bits/stdc++.h>
using namespace std;

using lnt = long long;
template <class T> using SET = unordered_set<T>;
template <class T, class S> using MAP = unordered_map<T, S>;

#define LOOP(n) for (lnt _ = 0; _ < (n); _++)     // 0, 1, ..., n-1
#define ILOOP(n) for (lnt _ = (n)-1; _ >= 0; _--) // n-1, n-2, ..., 0
#define REP(i, n) for (lnt i = 0; i < (n); i++)
#define IREP(i, n) for (lnt i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (lnt i = (a); i < (b); i++)     // a, a+1, ..., b-1
#define IFOR(i, a, b) for (lnt i = (b)-1; i >= (a); i--) // b-1, b-2, ..., a
#define ALL(a) a.begin(), a.end()

#define MAXELM max_element
#define MINELM min_element
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define PB push_back

// 'int'を一切タイプしない
#define MAIN int main

lnt inline POW(const lnt x, const lnt y) {
  lnt init = 1;
  for (lnt i = 0; i < y; i++) {
    init *= x;
  }
  return init;
}

lnt inline BIT(const lnt i) { return POW(2, i); }

// 非負整数valueのbase進数表示でのposition桁目を表示
lnt inline MASK(const lnt value, const lnt position, const lnt base = 10) {
  if (value >= 0 and base >= 2)
    return (value / POW(base, position)) % base;
  else {
    cout << "WARNING!" << endl;
    return 0;
  }
}

// ビットマスク
lnt inline BMASK(const lnt value, const lnt position) {
  return MASK(value, position, 2);
}

// MASKにおいて，position桁目に数字がない時0ではなくbaseを返す
lnt inline DIGIT(const lnt value, const lnt position, const lnt base = 10) {
  if (value >= 0 and base >= 2) {
    if (value == 0) {
      if (position == 0)
        return 0;
      else
        return base;
    } else {
      if (value < POW(base, position))
        return base;
      else
        return MASK(value, position, base);
    }
  } else {
    cout << "WARNING!" << endl;
    return 0;
  }
}

// base=2のDIGIT
lnt inline BDIGIT(const lnt value, const lnt position) {
  return DIGIT(value, position, 2);
}

const lnt INF = 2 * POW(10, 18); // cf. LLONG_MAX ≒ 9x10^18

template <class T, class S>
lnt inline CNT(const T &iteraterFirst, const T &iteraterLast, const S &value) {
  return (lnt)count(iteraterFirst, iteraterLast, value);
}

template <class T>
lnt inline DIST(const T &iteraterFirst, const T &iteraterLast) {
  return (lnt)distance(iteraterFirst, iteraterLast);
}

template <class T> lnt inline SIZE(const T &sequence) {
  return (lnt)(sequence.size());
}

template <class T> string inline STR(const T &value) {
  return to_string(value);
}

lnt inline ABS(const lnt &value) { return abs(value); }

lnt inline MAX(const lnt &value1, const lnt &value2) {
  return max(value1, value2);
}

lnt inline MIN(const lnt &value1, const lnt &value2) {
  return min(value1, value2);
}

MAIN() {
  lnt n;
  cin >> n;

  const MAP<lnt, lnt> mp3DigitTo357 = {{0, 3}, {1, 5}, {2, 7}};
  const SET<lnt> st012{0, 1, 2};

  lnt ans = 0;
  FOR(nDigit, 3, 10) {
    REP(cnt, POW(3, nDigit)) {
      lnt k = 0;
      SET<lnt> st3Digit;
      REP(pos, nDigit) {
        k += mp3DigitTo357.at(MASK(cnt, pos, 3)) * POW(10, pos);
        st3Digit.emplace(MASK(cnt, pos, 3));
      }
      if (k <= n and st3Digit == st012) {
        ans++;
      } else if (n < k) {
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384