Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

<image>

The problem is: 

You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n? 

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Examples

Input

4


Output

1


Input

7


Output

2


Input

77


Output

6
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, MAX = 1e18;
vector<long long> prim;
long long power(long long n) {
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    ans = ans * 2;
  }
  return ans;
}
long long isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return i;
    }
  }
  return 0;
}
long long fact(long long n) {
  long long ans = 1;
  for (long long i = 2; i <= n; i++) {
    ans = ans * i;
  }
  return ans;
}
void SoE(long long n) {
  prim.clear();
  for (long long i = 2; i <= n; i++) {
    if (isprime(i) == 0) {
      prim.push_back(i);
    }
  }
}
long long gc(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gc(a - b, b);
  return gc(a, b - a);
}
long long bis(vector<long long> a, long long n, long long k) {
  long long low = 0, high = n - 1, mid;
  long long ans = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (k < a[mid]) {
      high = mid - 1;
    } else if (k > a[mid]) {
      low = mid + 1;
    } else {
      ans = 1;
      break;
    }
  }
  if (ans == 1) {
    return mid;
  } else {
    return -1;
  }
}
class pehli {
 public:
  long long name;
  vector<long long> a;
} pehli;
long long fun(long long n) {
  long long ans = 0;
  while (n > 0) {
    long long l = n % 2;
    if (l == 1) ans++;
    n = n / 2;
  }
  return ans;
}
long long dTB(long long N) {
  long long B_Num = 0;
  int cn = 0;
  while (N != 0) {
    int r = N % 2;
    long long c = pow(10, cn);
    B_Num += r * c;
    N /= 2;
    cn++;
  }
  return B_Num;
}
string BTD(long long n) {
  long long m = n;
  string k = "";
  while (m > 0) {
    if (m % 10 == 0) {
      k = k + '1';
    } else {
      k = k + '0';
    }
    m = m / 10;
  }
  reverse(k.begin(), k.end());
  return k;
}
long long binToDec(string second) {
  bitset<64> bits(second);
  long long number = bits.to_ulong();
  return number;
}
long long middle(long long a, long long b) {
  if ((a + b) % 2 == 0)
    return (a + b) / 2;
  else
    return -1;
}
bool che(long long a, long long b, long long c) {
  if (a + b == 2 * c) {
    return true;
  } else if (a + c == 2 * b) {
    return true;
  } else if (b + c == 2 * a) {
    return true;
  } else {
    return false;
  }
}
long long mi = MAX;
vector<long long> adj[200001];
vector<long long> a(100001);
bool visited[100001] = {false};
void add_Edge(int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void remove_edge(int u, int v) {}
void dfs(long long n) {
  visited[n] = true;
  for (auto i : adj[n]) {
    if (visited[i] == false) {
      dfs(i);
    }
  }
}
string change(string u) {
  for (long long i = 0; i < u.length(); i++) {
    u[i] = 1 - (u[i] - '0');
  }
  return u;
}
bool ch(vector<long long> a) {
  long long sum = 0;
  for (long long i = 0; i < a.size(); i++) {
    sum = sum + a[i];
    if (sum < 0) return false;
  }
  if (sum == 0)
    return true;
  else
    return false;
}
bool sortbysec(const pair<int, pair<long long, long long> > &a,
               const pair<int, pair<long long, long long> > &b) {
  return a.second.first < b.second.first;
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  {
    vector<long long> a, b;
    map<long long, long long> make_pair, mp1;
    string blank;
    long long ans = 0, n, l = 0, k = 0, sum = 0, j = 0, m = 0, ans1 = 0,
              ans2 = 0, r = 0, sum1 = 0, sum2 = 0;
    cin >> n;
    long long n1 = n;
    string second = "";
    while (n1 > 0) {
      l++;
      k = n1 % 10;
      if (k == 4)
        second = second + '0';
      else
        second = second + '1';
      n1 = n1 / 10;
    }
    for (int i = 0; i < second.size(); i++) {
      if (second[i] == '1') {
        ans1 = ans1 + pow(2, i);
      }
    }
    for (long long i = 1; i <= l - 1; i++) {
      ans = ans + pow(2, i);
    }
    ans = ans + ans1 + 1;
    cout << ans;
  }
  return 0;
}
