One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.

But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input

Input data contains the only number n (1 ≤ n ≤ 109).

Output

Output the only number — answer to the problem.

Examples

Input

10


Output

2

Note

For n = 10 the answer includes numbers 1 and 10.
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
int a[20];
long long dp[20];
long long dfs(int pos, bool lead, bool limit) {
  if (pos == -1) return 1;
  if (!limit && !lead && dp[pos] != -1) return dp[pos];
  int up = limit ? a[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    if (i == 1) {
      ans += dfs(pos - 1, false, limit && i == a[pos]);
    } else if (i == 0) {
      ans += dfs(pos - 1, lead, limit && i == a[pos]);
    } else {
      continue;
    }
  }
  if (!limit && !lead) dp[pos] = ans;
  return ans;
}
long long solve(long long x) {
  int pos = 0;
  while (x) {
    a[pos++] = x % 10;
    x /= 10;
  }
  return dfs(pos - 1, true, true);
}
int main() {
  long long n;
  scanf("%lld", &n);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", solve(n) - 1);
  return 0;
}
