#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ri register int
#define rep(io, st, ed) for(int io = st; io <= ed; io ++)
#define drep(io, ed, st) for(int io = ed; io >= st; io --)

#define gc getchar
inline int read() {
	int p = 0, w = 1; char c = gc();
	while(c > '9' || c < '0') { if(c == '-') w = - 1; c = gc(); }
	while(c >= '0' && c <= '9') p = p * 10  + c - '0', c = gc();
	return p * w;
}

const int limn = 8e5 + 5;

int n, far, lst, cnt;
int cap[limn], node[limn], nxt[limn], dep[limn], maxd[limn], son[limn];

void addedge(int u, int v) {
	nxt[++ cnt] = cap[u]; cap[u] = cnt; node[cnt] = v;
}

void dfs(int o, int fa) {
	#define cur node[i]
	maxd[o] = o; son[o] = 0;
	for(int i = cap[o]; i; i = nxt[i]) if(fa != cur) {
		dep[cur] = dep[o] + 1;
		dfs(cur, o);
		if(dep[ maxd[cur] ] > dep[ maxd[o] ]) 
			maxd[o] = maxd[cur], son[o] = cur;
	}
}

int E[limn];
void dfs2(int o, int fa) {
	E[o] = E[lst] + dep[o] + dep[lst] - 2 * dep[fa]; lst = o;
	for(int i = cap[o]; i; i = nxt[i]) 
		if(cur != fa && cur != son[o]) dfs2(cur, o);
	if(son[o]) dfs2(son[o], o);
}

int main() {
	n = read();
	rep(i, 2, n) {
		int u = read(), v = read();
		addedge(u, v); addedge(v, u);
	}
	dfs(1, 0); //find the diamter
	int u = maxd[1];
	dep[u] = 1; dfs(u, 0); //reset it!
	dfs2(u, 0);
	rep(i, 1, n) printf("%d ", E[i]); printf("\n");
	return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END


const int N = 2e5 + 5;


void solve(){
    
    int n;
    cin >> n;
    int ans = n;
    int x = 1, y = 0;

    while(x <= n){
        int z = y + n / x + (n % x);
        x *= 2;
        y++;
        mini(ans, z);
    }
    
    cout << ans << endl;


}




signed main() {

    #ifdef LOCAL
        (void)!freopen("input.txt","r",stdin);
        (void)!freopen("output.txt","w",stdout);
    #endif
    
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
    return 0;
}

int powm(int a, int b){
    int res = 1;
    while (b) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}

