#include <stdio.h>
#include<string.h>
long long twos_complement_to_int(const char *bstr){
    int n = strlen(bstr);
    long long value = 0;
    for(int i = 0; i < n; i++)
    {
        value = (value << 1) + (bstr[i] - '0');
    }
    if (bstr[0] == '1')
    {
        value -= (1LL << n);
    }
    return value;
}
int main(void)
{
    char s[40];
    if (scanf("%39s",s) != 1){
        printf("Invalid Input";
        return o;)
    }
    for (int i = 0; i < len; i++)
    {
        if (s[i] != '0' && s[i] != '1')
        {
            printf("Invalid Input");
            return o;
        }
    }
    long long ans =
    twos_complement_to_int(s);
    printf("%lld",ans);
    return 0;
}