#include <bits/stdc++.h>
using namespace std;
string S;
int N;
int Ans = 0;
int Cnt3 = 1, Cnt5 = 1, Cnt7 = 1;
int bit = 1;
string T = "357";
int main() {
  cin >> S;
  N = atoi(S.c_str());
  int Len = S.length();
  for (int i = 0; i < Len - 3; i++) T = '0' + T;
  while (atoi(T.c_str()) <= N) {
    if (!Cnt3 || !Cnt5 || !Cnt7) {
    } else
      ++Ans;
    char ch = T[Len - 1];
    if (ch == '0') {
      ++Cnt3;
      T[Len - 1] = '3';
    } else if (ch == '3') {
      --Cnt3, ++Cnt5;
      T[Len - 1] = '5';
    } else if (ch == '5') {
      --Cnt5, ++Cnt7;
      T[Len - 1] = '7';
    } else {
      bit = 1;
      while (T[Len - bit] == '7') {
        --Cnt7, ++Cnt3;
        T[Len - bit] = '3';
        ++bit;
      }
      ch = T[Len - bit];
      if (ch == '0') {
        ++Cnt3;
        T[Len - bit] = '3';
      } else if (ch == '3') {
        --Cnt3, ++Cnt5;
        T[Len - bit] = '5';
      } else if (ch == '5') {
        --Cnt5, ++Cnt7;
        T[Len - bit] = '7';
      }
    }
  }
  cout << Ans << endl;
  return 0;
}
