#include <bits/stdc++.h>
using namespace std;
int v[500];
int a[2000000], b[2000000];
int d[30000] = {
    357,    375,    537,    573,    735,    753,    3357,   3375,   3537,
    3557,   3573,   3575,   3577,   3735,   3753,   3755,   3757,   3775,
    5337,   5357,   5373,   5375,   5377,   5537,   5573,   5733,   5735,
    5737,   5753,   5773,   7335,   7353,   7355,   7357,   7375,   7533,
    7535,   7537,   7553,   7573,   7735,   7753,   33357,  33375,  33537,
    33557,  33573,  33575,  33577,  33735,  33753,  33755,  33757,  33775,
    35337,  35357,  35373,  35375,  35377,  35537,  35557,  35573,  35575,
    35577,  35733,  35735,  35737,  35753,  35755,  35757,  35773,  35775,
    35777,  37335,  37353,  37355,  37357,  37375,  37533,  37535,  37537,
    37553,  37555,  37557,  37573,  37575,  37577,  37735,  37753,  37755,
    37757,  37775,  53337,  53357,  53373,  53375,  53377,  53537,  53557,
    53573,  53575,  53577,  53733,  53735,  53737,  53753,  53755,  53757,
    53773,  53775,  53777,  55337,  55357,  55373,  55375,  55377,  55537,
    55573,  55733,  55735,  55737,  55753,  55773,  57333,  57335,  57337,
    57353,  57355,  57357,  57373,  57375,  57377,  57533,  57535,  57537,
    57553,  57573,  57733,  57735,  57737,  57753,  57773,  73335,  73353,
    73355,  73357,  73375,  73533,  73535,  73537,  73553,  73555,  73557,
    73573,  73575,  73577,  73735,  73753,  73755,  73757,  73775,  75333,
    75335,  75337,  75353,  75355,  75357,  75373,  75375,  75377,  75533,
    75535,  75537,  75553,  75573,  75733,  75735,  75737,  75753,  75773,
    77335,  77353,  77355,  77357,  77375,  77533,  77535,  77537,  77553,
    77573,  77735,  77753,  333357, 333375, 333537, 333557, 333573, 333575,
    333577, 333735, 333753, 333755, 333757, 333775, 335337, 335357, 335373,
    335375, 335377, 335537, 335557, 335573, 335575, 335577, 335733, 335735,
    335737, 335753, 335755, 335757, 335773, 335775, 335777, 337335, 337353,
    337355, 337357, 337375, 337533, 337535, 337537, 337553, 337555, 337557,
    337573, 337575, 337577, 337735, 337753, 337755, 337757, 337775, 353337,
    353357, 353373, 353375, 353377, 353537, 353557, 353573, 353575, 353577,
    353733, 353735, 353737, 353753, 353755, 353757, 353773, 353775, 353777,
    355337, 355357, 355373, 355375, 355377, 355537, 355557, 355573, 355575,
    355577, 355733, 355735, 355737, 355753, 355755, 355757, 355773, 355775,
    355777, 357333, 357335, 357337, 357353, 357355, 357357, 357373, 357375,
    357377, 357533, 357535, 357537, 357553, 357555, 357557, 357573, 357575,
    357577, 357733, 357735, 357737, 357753, 357755, 357757, 357773, 357775,
    357777, 373335, 373353, 373355, 373357, 373375, 373533, 373535, 373537,
    373553, 373555, 373557, 373573, 373575, 373577, 373735, 373753, 373755,
    373757, 373775, 375333, 375335, 375337, 375353, 375355, 375357, 375373,
    375375, 375377, 375533, 375535, 375537, 375553, 375555, 375557, 375573,
    375575, 375577, 375733, 375735, 375737, 375753, 375755, 375757, 375773,
    375775, 375777, 377335, 377353, 377355, 377357, 377375, 377533, 377535,
    377537, 377553, 377555, 377557, 377573, 377575, 377577, 377735, 377753,
    377755, 377757, 377775, 533337, 533357, 533373, 533375, 533377, 533537,
    533557, 533573, 533575, 533577, 533733, 533735, 533737, 533753, 533755,
    533757, 533773, 533775, 533777, 535337, 535357, 535373, 535375, 535377,
    535537, 535557, 535573, 535575, 535577, 535733, 535735, 535737, 535753,
    535755, 535757, 535773, 535775, 535777, 537333, 537335, 537337, 537353,
    537355, 537357, 537373, 537375, 537377, 537533, 537535, 537537, 537553,
    537555, 537557, 537573, 537575, 537577, 537733, 537735, 537737, 537753,
    537755, 537757, 537773, 537775, 537777, 553337, 553357, 553373, 553375,
    553377, 553537, 553557, 553573, 553575, 553577, 553733, 553735, 553737,
    553753, 553755, 553757, 553773, 553775, 553777, 555337, 555357, 555373,
    555375, 555377, 555537, 555573, 555733, 555735, 555737, 555753, 555773,
    557333, 557335, 557337, 557353, 557355, 557357, 557373, 557375, 557377,
    557533, 557535, 557537, 557553, 557573, 557733, 557735, 557737, 557753,
    557773, 573333, 573335, 573337, 573353, 573355, 573357, 573373, 573375,
    573377, 573533, 573535, 573537, 573553, 573555, 573557, 573573, 573575,
    573577, 573733, 573735, 573737, 573753, 573755, 573757, 573773, 573775,
    573777, 575333, 575335, 575337, 575353, 575355, 575357, 575373, 575375,
    575377, 575533, 575535, 575537, 575553, 575573, 575733, 575735, 575737,
    575753, 575773, 577333, 577335, 577337, 577353, 577355, 577357, 577373,
    577375, 577377, 577533, 577535, 577537, 577553, 577573, 577733, 577735,
    577737, 577753, 577773, 733335, 733353, 733355, 733357, 733375, 733533,
    733535, 733537, 733553, 733555, 733557, 733573, 733575, 733577, 733735,
    733753, 733755, 733757, 733775, 735333, 735335, 735337, 735353, 735355};
int main() {
  int t;
  cin >> t;
  if (t < 357)
    cout << 0 << endl;
  else if (t >= 777777753)
    cout << 26484 << endl;
  else {
    for (int i = 0; i <= 26484; i++) {
      if (t < d[i]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
