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;
int digcount(int num) {
  int c = 0;
  while (num) {
    c++;
    num /= 10;
  }
  return c;
}
bool ones(int j) {
  int x = 0, num = j;
  while (num > 9) x = x * 10 + (num % 10), num /= 10;
  if (num > 1) return true;
  while (x) {
    if (x % 10 > 1)
      return true;
    else if (x % 10 == 0)
      return false;
    x /= 10;
  }
  if (j % 10 == 0) return false;
  return true;
}
unsigned long long power(int x, int p) {
  if (!p) return 1;
  return x * power(x, p - 1);
}
int bin(int num) {
  int x = 0, c = 0;
  while (num > 9) {
    if (num % 10 > 1)
      x = power(2, c + 1) - 1;
    else
      x += power(2, c) * (num % 10 > 0);
    c++;
    num /= 10;
  }
  return x;
}
int main() {
  int n;
  cin >> n;
  if (ones(n))
    cout << power(2, digcount(n)) - 1;
  else
    cout << power(2, digcount(n) - 1) + bin(n);
  return 0;
}
