// 霽れを待つ
#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
using namespace std;
const int N = 2e5 + 3;
struct Lst {int dir, nxt;}E[N<<1];
int G[N], cnt;
inline void Add(int u, int v) {
	E[++cnt].dir = v, E[cnt].nxt = G[u], G[u] = cnt;
}
int P, len;
void Pre_dfs(int u, int lst, int d) {
	(d > len) && (len = d, P = u);
	for(register int i=G[u];i;i=E[i].nxt) {
		int v = E[i].dir;
		if(v == lst) continue ;
		Pre_dfs(v, u, d + 1);
	}
}
int son[N], res[N];
int dfs(int u, int lst, int d) {
	int Mxd = d;
	for(register int i=G[u];i;i=E[i].nxt) {
		int v = E[i].dir;
		if(v == lst) continue ;
		int Mxv = dfs(v, u, d + 1);
		if(Mxv > Mxd) Mxd = Mxv, son[u] = v;
	}
	return Mxd;
}
int tot = 1;
void Fin_dfs(int u, int lst) {
	res[u] = tot;
	for(register int i=G[u];i;i=E[i].nxt) {
		int v = E[i].dir;
		if(v == lst || v == son[u]) continue ;
		tot ++ ;
		Fin_dfs(v, u);
		tot ++ ;
	}
	(son[u]) && (tot++, Fin_dfs(son[u], u), tot++);
}
int n;
int main() {
	scanf("%d", &n);
	forn(i,2,n) {
		static int u, v;
		scanf("%d%d", &u, &v);
		Add(u, v), Add(v, u);
	}
	Pre_dfs(1, -1, 0);
	dfs(P, -1, 1);
	Fin_dfs(P, -1);
	forn(i,1,n) printf("%d%c", res[i], " \n"[i == n]);
	return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;
    vector<string> s(h); rep (i, h) cin >> s[i];
    ll ans = 0;
    rep (i, h - 1) rep (j, w - 1) {
        int x = 0;
        rep (p, 2) rep (q, 2) x += (s[i + p][j + q] == '#');
        if (x == 1 || x == 3) ans++;
    }
    cout << ans << "\n";
    return 0;
}