#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(int i = begin; i < (int)(end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
const ll INF = 1e9;
const double EPS = 1e-10;
/* #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using d32 = mp::number<mp::cpp_dec_float<32>>; */
const ll MOD = 1e9 + 7;
/* #include <atcoder/all>
using namespace atcoder;
using mint = modint; */
using P = pair<int, int>;
using Graph = vector<vector<int>>;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // mint::set_mod(MOD);
    
    string s;
    cin >> s;
    
    while(s.back() == '0') s.erase(s.end() - 1);
    string t = s;
    reverse(all(t));
    cout << (s == t ? "Yes" : "No") << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>

int main() {
    FAST

    ll n;   cin>>n;
    ll b=0, cur=1, ans=n;

    while(cur<=n){
        ll a=n/cur;
        ll c=n%cur;
        ans=min(ans, a+b+c);

        b++;
        cur*=2;
    }

    cout<<ans<<endl;

    return 0;
}