#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;
}
// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cmath>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
    }
    
    int ans = 0;
    rep(i, n) {
        queue<int> q;
        vector<int> ch(n, 0);
        q.push(i);
        ch[i] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int u : g[v]) {
                if (exchange(ch[u], 1) == 0) q.push(u);
            }
        }
        ans += accumulate(all(ch), 0);
    }
    cout << ans << '\n';
}
