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;
char *opos, OutFile[65536], DIP[20];
FILE *pfile;
inline void InitFASTIO() { opos = OutFile; }
inline void FlushFASTIO() { fwrite(OutFile, opos - OutFile, 1, stdout); }
inline void fps(int &x) {
  register int c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
inline void fs(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void fl(long long int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void pi(int x, int flag = 1) {
  int y, dig = 0;
  if (x < 0) {
    *opos++ = '-';
    x = -x;
  };
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
  while (x || !dig) {
    y = x / 10;
    DIP[dig++] = x - ((y << 3) + (y << 1)) + '0';
    x = y;
  }
  while (dig--) {
    *opos++ = DIP[dig];
    if (opos - OutFile == (sizeof(OutFile) - 1)) {
      FlushFASTIO();
      InitFASTIO();
    }
  }
  *opos++ = flag ? '\n' : ' ';
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
}
inline void pll(long long int x, int flag = 1) {
  long long int y, dig = 0;
  if (x < 0) {
    *opos++ = '-';
    x = -x;
  };
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
  while (x || !dig) {
    y = x / 10;
    DIP[dig++] = x - ((y << 3) + (y << 1)) + '0';
    x = y;
  }
  while (dig--) {
    *opos++ = DIP[dig];
    if (opos - OutFile == (sizeof(OutFile) - 1)) {
      FlushFASTIO();
      InitFASTIO();
    }
  }
  *opos++ = flag ? '\n' : ' ';
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
}
inline void ps(char *str, int flag = 1) {
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    *opos++ = str[i];
    if (opos - OutFile == (sizeof(OutFile) - 1)) {
      FlushFASTIO();
      InitFASTIO();
    }
  }
  *opos++ = flag ? '\n' : ' ';
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
}
inline void pws(int flag = 1) {
  *opos++ = flag ? '\n' : ' ';
  if (opos - OutFile == (sizeof(OutFile) - 1)) {
    FlushFASTIO();
    InitFASTIO();
  }
}
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
bool isDigit(char xx) { return ('0' <= xx && xx <= '9'); }
bool isCharacter(char xx) {
  return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
bool isUpper(char xx) { return ('A' <= xx && xx <= 'Z'); }
bool isLower(char xx) { return ('a' <= xx && xx <= 'z'); }
bool isPalin(string x) {
  int len = x.length();
  for (long long i = 0; i < len / 2; i++) {
    if (x[i] != x[len - 1 - i]) return false;
  }
  return true;
}
void swapInt(int &x, int &y) {
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
}
string tolowerStr(string x) {
  string ret = "";
  for (long long i = 0; i < x.length(); i++) {
    ret.push_back(tolower(x[i]));
  }
  return ret;
}
string toupperStr(string x) {
  string ret = "";
  for (long long i = 0; i < x.length(); i++) {
    ret.push_back(toupper(x[i]));
  }
  return ret;
}
void toCharArray(char *dest, string source) { strcpy(dest, source.c_str()); }
int main() {
  InitFASTIO();
  long long n;
  fl(n);
  long long len = log10(double(n)) + 1;
  long long sum = 0;
  for (long long i = 0; i < len - 1; i++) {
    sum += pow(2.0, double(i));
  }
  long long x = n;
  int flag = 0;
  int dig;
  for (int i = 0; i < len; i++) {
    long long a = 1, b = 1, c = 1;
    for (long long k = 0; k < len - i - 1; k++) a = a * 10;
    for (long long k = 0; k < len - i; k++) b = b * 2;
    for (long long k = 0; k < len - i - 1; k++) c = c * 2;
    dig = (x / a) % 10;
    if (dig > 1 && i != 0) {
      flag = 1;
      sum += (b);
      break;
    } else if (dig > 1) {
      flag = 1;
      sum += (c);
      break;
    } else if (dig == 1 && i != 0) {
      sum += (c);
    }
  }
  if (flag != 1) sum++;
  cout << sum << endl;
  FlushFASTIO();
  return 0;
}
