#include <bits/stdc++.h>
using namespace std;
int vis[10];
int a[4] = {0, 3, 5, 7};
int main() {
  vector<int> v;
  int t;
  scanf("%d", &t);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int k1 = 0; k1 < 4; k1++) {
          for (int k2 = 0; k2 < 4; k2++) {
            for (int k3 = 0; k3 < 4; k3++) {
              for (int k4 = 0; k4 < 4; k4++) {
                for (int k5 = 0; k5 < 4; k5++) {
                  for (int k6 = 0; k6 < 4; k6++) {
                    vis[a[i]] = 1;
                    vis[a[j]] = 1;
                    vis[a[k]] = 1;
                    vis[a[k1]] = 1;
                    vis[a[k2]] = 1;
                    vis[a[k3]] = 1;
                    vis[a[k4]] = 1;
                    vis[a[k5]] = 1;
                    vis[a[k6]] = 1;
                    int ans = a[i] * 100000000 + a[j] * 10000000 +
                              a[k] * 1000000 + a[k1] * 100000 + a[k2] * 10000 +
                              a[k3] * 1000 + a[k4] * 100 + a[k5] * 10 + a[k6];
                    int temp = ans;
                    int flag = 0;
                    while (temp) {
                      if (!(temp % 10 == 3 || temp % 10 == 5 || temp % 10 == 7))
                        flag = 1;
                      temp = temp / 10;
                    }
                    if (!flag && ans < t && vis[3] && vis[5] && vis[7]) {
                      v.push_back(ans);
                    }
                    memset(vis, 0, sizeof(vis));
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  printf("%d\n", v.size());
  return 0;
};
