#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long INFL = 9223372036854775807;
const long long mod = 1000000007;
int main() {
  string s;
  cin >> s;
  int res = 0;
  if (s[0] > '7') s[0] = '7';
  int n = stoi(s);
  for (int i = 0; i < int(n + 1); i++) {
    int j = i;
    bool a = false, b = false, c = false;
    bool d = true;
    while (j) {
      int k = j % 10;
      j /= 10;
      if (k == 3)
        a = true;
      else if (k == 5)
        b = true;
      else if (k == 7)
        c = true;
      else {
        d = false;
        break;
      }
    }
    if (a && b && c && d) res++;
    ;
  }
  cout << res << endl;
  return 0;
}
