#include <bits/stdc++.h>
using namespace std;
long long n;
set<long long> s, ans;
map<long long, long long> checking;
long long seven(long long x) {
  if (x >= 100000000000) return x;
  s.insert(x);
  seven(10 * x + 7);
}
long long f(long long x) {
  if (x >= 100000000000) return x;
  s.insert(x);
  seven(10 * x + 5);
}
long long th(long long x) {
  if (x >= 100000000000) return x;
  s.insert(x);
  seven(10 * x + 3);
}
long long shichigosan(long long x, int pos, int sev, int five, int three) {
  string num = to_string(x);
  if (x >= 100000000000 || pos >= num.size()) return x;
  char temp = num[pos];
  long long t = 0;
  int seve = sev, fiv = five, thre = three;
  num[pos] = '7';
  seve++;
  t = stoll(num);
  if (!checking[t]) {
    if (seve > 0 && fiv > 0 && thre > 0) {
      ans.insert(t);
      checking[t]++;
    }
    shichigosan(t, pos + 1, seve, fiv, thre);
  }
  seve = sev;
  fiv = five;
  thre = three;
  num[pos] = temp;
  num[pos] = '5';
  fiv++;
  t = stoll(num);
  if (!checking[t]) {
    if (seve > 0 && fiv > 0 && thre > 0) {
      ans.insert(t);
      checking[t]++;
    }
    shichigosan(t, pos + 1, seve, fiv, thre);
  }
  seve = sev;
  fiv = five;
  thre = three;
  num[pos] = temp;
  num[pos] = '3';
  thre++;
  t = stoll(num);
  if (!checking[t]) {
    if (seve > 0 && fiv > 0 && thre > 0) {
      ans.insert(t);
      checking[t]++;
    }
    shichigosan(t, pos + 1, seve, fiv, thre);
  }
  seve = sev;
  fiv = five;
  thre = three;
  num[pos] = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  seven(777);
  f(555);
  th(333);
  for (auto it = s.begin(); it != s.end(); ++it) {
    shichigosan(*it, 0, 0, 0, 0);
  }
  cin >> n;
  long long c = 0;
  for (auto it = ans.begin(); it != ans.end(); ++it) {
    if (*it >= n) {
      cout << c;
      break;
    }
    c++;
  }
  return 0;
}
