#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:(ln + 1);
	if (g[v].size() != 1) new_len = -1;
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		dist[to] = dist[v] + 1;
		int get = dfs(to, v, new_len);
		if (get == -1) go_up = -1;
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0 && go_up != -1){
		go_up = 1;
	}
	if (lens.size() == 1 && go_up != -1){
		go_up = 1+*lens.begin();
	}
	int lenn = lens.size();
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln)))
		go_up = -1;
	if (ln != -1 && go_up != -1){
		if (ln != 0)
			lens.insert(ln);
		if (lens.size() < 3){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	int next_one = 0;
	for (int i = 1; i <= n; i++){
		if (i != start && g[i].size() == 1)
		{
			if (dist[next_one] < dist[i])
				next_one = i;
		}
	}
	dfs(next_one);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:(ln + 1);
	if (ln == 0){
		if (g[v].size() != 1) new_len = -1;
	}
	else {
		if (g[v].size() != 2) new_len = -1;
	}
	//if ((g[v].size() != 1 && ln != 0) || (g[v].size() != 2 && ln == 0)) new_len = -1;
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		dist[to] = dist[v] + 1;
		int get = dfs(to, v, new_len);
		if (get == -1) go_up = -1;
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0 && go_up != -1){
		go_up = 1;
	}
	if (lens.size() == 1 && go_up != -1){
		go_up = 1+*lens.begin();
	}
	int lenn = lens.size();
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln)))
		go_up = -1;
	if (ln != -1 && go_up != -1){
		if (ln != 0)
			lens.insert(ln);
		if (lens.size() < 3){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	/*int next_one = 0;
	for (int i = 1; i <= n; i++){
		if (i != start && g[i].size() == 1)
		{
			if (dist[next_one] < dist[i])
				next_one = i;
		}
	}
	dfs(next_one);*/
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;
int tt = -1;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = ln + 1, go_up = 0;
	if (ln == -1 || g[v].size() > 2) new_len = -1;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1)
			return -1;
		else
			lens.insert(get);
	}
	if (lens.size() == 0)
		go_up = 1;
	if (lens.size() == 1)
		go_up = 1+*lens.begin();
	int lenn = lens.size();
	if ((lens.size() == 1 && ln != -1) || (lens.size() == 2 && !lens.count(ln))){
		tt = v;
	}
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln))){
		return -1;
	}
	if (ln != -1){
		lens.insert(ln);
		lens.erase(0);
		set<int>::iterator it;
		int temp = 0;
		for (it = lens.begin(); it != lens.end(); it++){
			temp += *it;
		}
		while (temp % 2 == 0) temp /= 2;
		ans = min(ans, temp);
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	dfs(tt);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = ln + 1, go_up = 0;
	if (ln == -1 || g[v].size() > 2) new_len = -1;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1)
			return -1;
		else
			lens.insert(get);
	}
	if (lens.size() == 0)
		go_up = 1;
	if (lens.size() == 1)
		go_up = 1+*lens.begin();
	int lenn = lens.size();
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln))){
		return -1;
	}
	if (ln != -1){
		lens.insert(ln);
		lens.erase(0);
		if (lens.size() < 3 && lens.size() > 0){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;
int root = -1;

void try_update(set<int> s){
	int tmp = 0;
	for (set<int>::iterator it = s.begin(); it != s.end(); it++)
		tmp += *it;
	while (tmp % 2 == 0) tmp /= 2;
	ans = min(ans, tmp);
}

int dfs(int v, int p = 0){
	set<int> s;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v);
		if (get == -1) return -1;
		s.insert(get);
	}
	if (s.size() == 0){
		return 1;
	}
	if (s.size() == 1){
		if (p == 0)
			try_update(s);
		return 1 + *s.begin();
	}
	if (s.size() == 2){
		if (p == 0)
			try_update(s);
		root = v;
	}
	if (s.size() > 1) return -1;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1);
	if (root != -1) dfs(root);
	if (ans == 1e9) cout << -1; else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:(ln + 1);
	if (g[v].size() != 1) new_len = -1;
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == 0){
			int ss = 213;
		}
		if (get == -1) go_up = -1;
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0 && go_up != -1){
		go_up = 1;
	}
	if (lens.size() == 1 && go_up != -1){
		go_up = 1+*lens.begin();
	}
	if (lens.size() == 2){
		int d432 = 123;
	}
	if (lens.size() == 2){
		int s234 = 12;
	}
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln)))
		go_up = -1;
	if (ln != -1 && go_up != -1){
		if (ln != 0)
			lens.insert(ln);
		if (lens.size() < 3){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lens.size() > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dfs(start);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;
int tt = -1;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = ln + 1, go_up = 0;
	if (ln == -1 || g[v].size() > 2) new_len = -1;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1)
			return -1;
		else
			lens.insert(get);
	}
	if (lens.size() == 0)
		go_up = 1;
	if (lens.size() == 1)
		go_up = 1+*lens.begin();
	int lenn = lens.size();
	if ((lens.size() == 1 && ln != -1) || (lens.size() == 2 && !lens.count(ln))){
		tt = v;
	}
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln))){
		return -1;
	}
	if (ln != -1){
		lens.insert(ln);
		lens.erase(0);
		set<int>::iterator it;
		int temp = 0;
		for (it = lens.begin(); it != lens.end(); it++){
			temp += *it;
		}
		if (temp != 0){
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	dfs(tt);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:(ln + 1);
	if (ln == 0){
		if (g[v].size() != 1) new_len = -1;
	}
	else {
		if (g[v].size() != 2) new_len = -1;
	}
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1){
			return -1;
		}
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0){
		go_up = 1;
	}
	if (lens.size() == 1){
		go_up = 1+*lens.begin();
	}
	int lenn = lens.size();
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln))){
		return -1;
	}
	if (ln != -1 && go_up != -1){
		if (ln != 0)
			lens.insert(ln);
		else{
			int rfd = 2;
		}
		if (lens.size() < 3 && len.size() > 0){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	if (go_up == 0){
		int fef = 213;
	}
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	int next_one = 0;
	for (int i = 1; i <= n; i++){
		if (i != start && g[i].size() == 1)
		{
			if (dist[next_one] < dist[i])
				next_one = i;
		}
	}
	dfs(next_one);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int dist[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:(ln + 1);
	if (ln == 0){
		if (g[v].size() != 1) new_len = -1;
	}
	else {
		if (g[v].size() != 2) new_len = -1;
	}
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1){
			return -1;
		}
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0){
		go_up = 1;
	}
	if (lens.size() == 1){
		go_up = 1+*lens.begin();
	}
	int lenn = lens.size();
	if (lens.size() > 2 || (lens.size() == 2 && !lens.count(ln))){
		return -1;
	}
	if (ln != -1 && go_up != -1){
		if (ln != 0)
			lens.insert(ln);
		if (lens.size() < 3){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	if (lenn > 1) go_up = -1;
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dist[start] = 0;
	dfs(start);
	int next_one = 0;
	for (int i = 1; i <= n; i++){
		if (i != start && g[i].size() == 1)
		{
			if (dist[next_one] < dist[i])
				next_one = i;
		}
	}
	dfs(next_one);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;

ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll _gcd(ll a, ll b, ll & x, ll & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll _x1, _y1;
	ll d = _gcd(b%a, a, _x1, _y1);
	x = _y1 - (b / a) * _x1;
	y = _x1;
	return d;
}

ll binpow(ll a, ll n) {
	if (n == -1) return 0;
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		a %= mod;
		res %= mod;
	}
	return res;
}

const int N = 2e5 + 10;

vector<int> g[N];
int n;

int ans = 1e9;

int dfs(int v, int p = 0, int ln = 0){
	set<int> lens;
	int new_len = (ln == -1)?-1:ln + 1;
	if (g[v].size() != 1) new_len = -1;
	int go_up = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i];
		if (to == p) continue;
		int get = dfs(to, v, new_len);
		if (get == -1) go_up = -1;
		else{
			lens.insert(get);
		}
	}
	if (lens.size() == 0 && go_up != -1){
		go_up = 1;
	}
	if (lens.size() == 1 && go_up != -1){
		go_up = 1+*lens.begin();
	}
	if (lens.size() > 1) go_up = -1;
	if (ln != -1){
		if (ln != 0)
			lens.insert(ln);
		if (lens.size() == 1){
			int temp = *lens.begin();
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
		if (lens.size() == 2){
			set<int>::iterator it;
			int temp = 0;
			for (it = lens.begin(); it != lens.end(); it++){
				temp += *it;
			}
			while (temp % 2 == 0) temp /= 2;
			ans = min(ans, temp);
		}
	}
	return go_up;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int start = 1;
	while (g[start].size() > 1) start++;
	dfs(start);
	if (ans == 1e9) cout << -1;
	else cout << ans;
	return 0;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
vector<int>pat[200000];
vector<int>ko[200000];
bool flag[200000];
int dat[200000];
void dfs(int node)
{
	if(flag[node])return;
	flag[node]=true;
	for(int i=0;i<pat[node].size();i++)
	{
		if(!flag[pat[node][i]])
		{
			ko[node].push_back(pat[node][i]);
			dfs(pat[node][i]);
		}
	}
}
int root=-1;
void calc1(int node)
{
	if(ko[node].empty())dat[node]=0;
	int isr=0;
	for(int i=0;i<ko[node].size();i++)
	{
		calc1(ko[node][i]);
		if(dat[node]==-5)dat[node]=dat[ko[node][i]]+1;
		else if(dat[node]!=dat[ko[node][i]]+1)isr=1,dat[node]=-10;
	}
	if(root==-1&&isr==1)root=node;
}
void calc2(int node)
{
	if(ko[node].empty())dat[node]=0;
	for(int i=0;i<ko[node].size();i++)
	{
		calc2(ko[node][i]);
		if(dat[node]==-5)dat[node]=dat[ko[node][i]]+1;
		else if(dat[node]!=dat[ko[node][i]]+1)root=node,dat[node]=-1000000000;
	}
}
int main()
{
	int num;
	scanf("%d",&num);
	for(int i=0;i<num-1;i++)
	{
		int za,zb;
		scanf("%d%d",&za,&zb);
		za--,zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	fill(flag,flag+num,false);
	for(int i=0;i<num;i++)ko[i].clear(),dat[i]=-5;
	dfs(0);
	calc1(0);
	if(root==-1)root=0;
	//printf("%d\n",root+1);
	fill(flag,flag+num,false);
	for(int i=0;i<num;i++)ko[i].clear(),dat[i]=-5;
	dfs(root);
	calc2(root);
	//printf("%d\n",root+1);
	//for(int i=0;i<num;i++)printf("%d ",dat[i]);printf("\n");
	set<int>se;
	for(int i=0;i<ko[root].size();i++)
	{
		if(dat[ko[root][i]]<0)
		{
			printf("-1\n");
			return 0;
		}
		se.insert(dat[ko[root][i]]+1);
		//printf("%d ",dat[ko[root][i]]+1);
	}
	if(se.size()>=3)
	{
		printf("-1\n");
		return 0;
	}
	set<int>::iterator it=se.begin();
	int sum=0;
	for(;;)
	{
		if(it==se.end())break;
		sum+=*it;
		it++;
	}
	for(;;)
	{
		if(sum%2==1)break;
		sum/=2;
	}
	printf("%d\n",sum);
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
vector<int>pat[200000];
vector<int>ko[200000];
bool flag[200000];
set<int>dat1[200000];
set<int>dat2[200000];
int par[200000];
void dfs(int node)
{
	if(flag[node])return;
	flag[node]=true;
	for(int i=0;i<pat[node].size();i++)
	{
		if(!flag[pat[node][i]])
		{
			ko[node].push_back(pat[node][i]);
			par[pat[node][i]]=node;
			dfs(pat[node][i]);
		}
	}
}
void calc1(int node)
{
	for(int i=0;i<ko[node].size();i++)calc1(ko[node][i]);
	for(int i=0;i<ko[node].size();i++)
	{
		set<int>::iterator it=dat1[ko[node][i]].begin();
		for(;;)
		{
			if(dat1[node].size()>=3)break;
			if(it==dat1[ko[node][i]].end())break;
			dat1[node].insert((*it)+1);
			it++;
		}
	}
	if(ko[node].empty())dat1[node].insert(0);
}
void calc2(int node)
{
	if(node==0&&ko[node].size()==1)dat2[node].insert(0);
	for(int i=0;i<ko[node].size();i++)
	{
		set<int>::iterator it=dat2[node].begin();
		for(;;)
		{
			if(it==dat2[node].end())break;
			dat2[ko[node][i]].insert((*it)+1);
			it++;
		}
	}
	set<int>now;
	for(int i=0;i<ko[node].size();i++)
	{
		set<int>::iterator it=now.begin();
		for(;;)
		{
			if(it==now.end())break;
			dat2[ko[node][i]].insert((*it)+1);
			it++;
		}
		it=dat1[ko[node][i]].begin();
		for(;;)
		{
			if(now.size()>=3)break;
			if(it==dat1[ko[node][i]].end())break;
			now.insert((*it)+1);
			it++;
		}
	}
	now.clear();
	for(int i=int(ko[node].size())-1;i>=0;i--)
	{
		set<int>::iterator it=now.begin();
		for(;;)
		{
			if(it==now.end())break;
			dat2[ko[node][i]].insert((*it)+1);
			it++;
		}
		it=dat1[ko[node][i]].begin();
		for(;;)
		{
			if(now.size()>=3)break;
			if(it==dat1[ko[node][i]].end())break;
			now.insert((*it)+1);
			it++;
		}
	}
	for(int i=0;i<ko[node].size();i++)calc2(ko[node][i]);
}
int main()
{
	int num;
	scanf("%d",&num);
	for(int i=0;i<num-1;i++)
	{
		int za,zb;
		scanf("%d%d",&za,&zb);
		za--,zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	dfs(0);
	calc1(0);
	calc2(0);
	int mini=1000000000;
	for(int i=0;i<num;i++)
	{
		/*printf("%d   ",i+1);
		set<int>::iterator xxx=dat1[i].begin();
		for(;;)
		{
			if(xxx==dat1[i].end())break;
			printf("%d ",*xxx);
			xxx++;
		}
		printf("    ");*/
		set<int>::iterator it=dat2[i].begin();
		for(;;)
		{
			if(it==dat2[i].end())break;
			//printf("%d ",*it);
			dat1[i].insert(*it);
			it++;
		}
		//printf("\n");
		if(dat1[i].size()==2)
		{
			int mm=dat2[i].size();
			for(int j=0;j<ko[i].size();j++)mm=max(mm,int(dat1[ko[i][j]].size()));
			if(mm>=2)continue;
			it=dat1[i].begin();
			int x=*it;
			it++;
			x+=*it;
			for(;;)
			{
				if(x%2==0)x/=2;
				else break;
			}
			mini=min(mini,x);
		}
	}
	if(mini==1000000000)printf("-1\n");
	else printf("%d\n",mini);
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
vector<int>pat[200000];
vector<int>ko[200000];
bool flag[200000];
int dat[200000];
void dfs(int node)
{
	if(flag[node])return;
	flag[node]=true;
	for(int i=0;i<pat[node].size();i++)
	{
		if(!flag[pat[node][i]])
		{
			ko[node].push_back(pat[node][i]);
			dfs(pat[node][i]);
		}
	}
}
int root=-1;
void calc1(int node)
{
	if(root!=-1)return;
	if(ko[node].empty())dat[node]=0;
	for(int i=0;i<ko[node].size();i++)
	{
		if(root!=-1)return;
		calc1(ko[node][i]);
		if(dat[node]==-5)dat[node]=dat[ko[node][i]]+1;
		else if(dat[node]!=dat[ko[node][i]]+1)root=node,dat[node]=-10;
	}
}
void calc2(int node)
{
	if(ko[node].empty())dat[node]=0;
	for(int i=0;i<ko[node].size();i++)
	{
		calc2(ko[node][i]);
		if(dat[node]==-5)dat[node]=dat[ko[node][i]]+1;
		else if(dat[node]!=dat[ko[node][i]]+1)root=node,dat[node]=-1000000000;
	}
}
int main()
{
	int num;
	scanf("%d",&num);
	for(int i=0;i<num-1;i++)
	{
		int za,zb;
		scanf("%d%d",&za,&zb);
		za--,zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	fill(flag,flag+num,false);
	for(int i=0;i<num;i++)ko[i].clear(),dat[i]=-5;
	dfs(0);
	calc1(0);
	if(root==-1)root=0;
	//printf("%d\n",root+1);
	fill(flag,flag+num,false);
	for(int i=0;i<num;i++)ko[i].clear(),dat[i]=-5;
	dfs(root);
	calc2(root);
	//printf("%d\n",root+1);
	//for(int i=0;i<num;i++)printf("%d ",dat[i]);printf("\n");
	set<int>se;
	for(int i=0;i<ko[root].size();i++)
	{
		if(dat[ko[root][i]]<0)
		{
			printf("-1\n");
			return 0;
		}
		se.insert(dat[ko[root][i]]+1);
		//printf("%d ",dat[ko[root][i]]+1);
	}
	if(se.size()>=3)
	{
		printf("-1\n");
		return 0;
	}
	set<int>::iterator it=se.begin();
	int sum=0;
	for(;;)
	{
		if(it==se.end())break;
		sum+=*it;
		it++;
	}
	for(;;)
	{
		if(sum%2==1)break;
		sum/=2;
	}
	printf("%d\n",sum);
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:268435456")

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cassert>
#include <memory.h>
#include <ctime>
#include <cmath>
#include <complex>

//#include <unordered_set>
//#include <unordered_map>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i < int(n); ++i)
#define fork(i, k, n) for(int i = int(k); i <= int(n); ++i)
#define forft(i, from, to) for(int i = int(from); i < int(to); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define mnp(a, b) make_pair((a) < (b) ? (a) : (b), (a) < (b) ? (b) : (a))
#define sz(d) int(d.size())
#define all(a) a.begin(), a.end()
#define ms(a, v) memset(a, v, sizeof(a))
#define msn(a, v, n) memset(a, v, n * sizeof(a[0]))
#define X first
#define Y second
#define correct(x, y, xmax, ymax) ((x) >= 0 && (x) < (xmax) && (y) >= 0 && (y) < (ymax))

template<typename T> T sqr(const T &x) {
	return x * x;
}

template<typename T> T my_abs(const T &x) {
	return x < 0 ? -x : x;
}

typedef long long li;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long uli;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<li,li> pli;
typedef pair<ld,ld> pd;

const int INF = (int)1e9;
const li LINF = (li)6e18;
const li INF64 = LINF;
const li INFLL = LINF;
const ld EPS = 1e-15;
const ld PI = 3.1415926535897932384626433832795;
const ld ME = 1e-5;
const li MOD2 = (int)1e9 + 21;
const int SQN = 320;
const int LOGN = 17;

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

const int N = (int)2e5 + 10;
const int M = 26;
const li MOD = (int)1e9 + 7;

vector<int> g[N];

int n;

int d[N];

int len[N];

int par[N];

void dfs(int v, int p) {
	len[v] = -1;
	if (sz(g[v]) == 1) {
		len[v] = 0;
		return;
	}
	forn(i, sz(g[v])) {
		int u = g[v][i];
		if (u == p) {
			continue;
		}
		dfs(u, v);
		if (len[v] == -1) {
			len[v] = len[u] + 1;
		} else if (len[v] != len[u] + 1) {
			printf("-1\n");
			exit(0);
		}
	}
}

void solve() {
	scanf("%d", &n);
	forn(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = 0;
	queue<int> q;
	ms(d, -1);
	d[st] = 0;
	q.push(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		forn(i, sz(g[v])) {
			int u = g[v][i];
			if (d[u] == -1) {
				d[u] = d[v] + 1;
				q.push(u);
			}
		}
	}
	st = 0;
	forn(v, n) {
		if (d[v] > d[st]) {
			st = v;
		}
	}
	ms(d, -1);
	d[st] = 0;
	par[st] = -1;
	q.push(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		forn(i, sz(g[v])) {
			int u = g[v][i];
			if (d[u] == -1) {
				d[u] = d[v] + 1;
				par[u] = v;
				q.push(u);
			}
		}
	}
	int mn = 0;
	forn(v, n) {
		if (d[v] > d[mn]) {
			mn = v;
		}
	}
	vector<int> path;
	while(mn != st) {
		path.pb(mn);
		mn = par[mn];
	}
	path.pb(st);
	int r = path[sz(path) / 2];
	vector<int> lens;
	forn(i, sz(g[r])) {
		int u = g[r][i];
		dfs(u, r);
		lens.pb(len[u] + 1);
	}
	sort(all(lens));
	lens.erase(unique(all(lens)), lens.end());
	if (sz(lens) > 2) {
		printf("-1\n");
		return;
	}
	int sum = 0;
	forn(i, sz(lens)) {
		sum += lens[i];
	}
	while (!(sum & 1)) {
		sum = sum >> 1;
	}
	printf("%d\n", sum);
}

int main() {
	ios_base::sync_with_stdio(false);
#ifdef SU2
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	srand((unsigned int)time(NULL));

	cout << setprecision(15) << fixed;

	solve();

#ifdef SU2
	cerr << "time: " << clock() << " ms" << endl;
#endif

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:268435456")

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cassert>
#include <memory.h>
#include <ctime>
#include <cmath>
#include <complex>

//#include <unordered_set>
//#include <unordered_map>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i < int(n); ++i)
#define fork(i, k, n) for(int i = int(k); i <= int(n); ++i)
#define forft(i, from, to) for(int i = int(from); i < int(to); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define mnp(a, b) make_pair((a) < (b) ? (a) : (b), (a) < (b) ? (b) : (a))
#define sz(d) int(d.size())
#define all(a) a.begin(), a.end()
#define ms(a, v) memset(a, v, sizeof(a))
#define msn(a, v, n) memset(a, v, n * sizeof(a[0]))
#define X first
#define Y second
#define correct(x, y, xmax, ymax) ((x) >= 0 && (x) < (xmax) && (y) >= 0 && (y) < (ymax))

template<typename T> T sqr(const T &x) {
	return x * x;
}

template<typename T> T my_abs(const T &x) {
	return x < 0 ? -x : x;
}

typedef long long li;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long uli;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<li,li> pli;
typedef pair<ld,ld> pd;

const int INF = (int)1e9;
const li LINF = (li)6e18;
const li INF64 = LINF;
const li INFLL = LINF;
const ld EPS = 1e-15;
const ld PI = 3.1415926535897932384626433832795;
const ld ME = 1e-5;
const li MOD2 = (int)1e9 + 21;
const int SQN = 320;
const int LOGN = 17;

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

const int N = (int)2e5 + 10;
const int M = 26;
const li MOD = (int)1e9 + 7;

vector<int> g[N];

int n;

int d[N];

int len[N];

void dfs(int v, int p) {
	len[v] = -1;
	if (sz(g[v]) == 1) {
		len[v] = 0;
		return;
	}
	forn(i, sz(g[v])) {
		int u = g[v][i];
		if (u == p) {
			continue;
		}
		dfs(u, v);
		if (len[v] == -1) {
			len[v] = len[u] + 1;
		} else if (len[v] != len[u] + 1) {
			printf("-1\n");
			exit(0);
		}
	}
}

void solve() {
	scanf("%d", &n);
	forn(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = 0;
	queue<int> q;
	ms(d, -1);
	d[st] = 0;
	q.push(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		forn(i, sz(g[v])) {
			int u = g[v][i];
			if (d[u] == -1) {
				d[u] = d[v] + 1;
				q.push(u);
			}
		}
	}
	st = 0;
	forn(v, n) {
		if (d[v] > d[st]) {
			st = v;
		}
	}
	ms(d, -1);
	d[st] = 0;
	q.push(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		forn(i, sz(g[v])) {
			int u = g[v][i];
			if (d[u] == -1) {
				d[u] = d[v] + 1;
				q.push(u);
			}
		}
	}
	st = 0;
	forn(v, n) {
		if (d[v] > d[st]) {
			st = v;
		}
	}
	int r = -1;
	forn(v, n) {
		if (d[v] == d[st] / 2) {
			r = v;
			break;
		}
	}
	assert(r != -1);
	vector<int> lens;
	forn(i, sz(g[r])) {
		int u = g[r][i];
		dfs(u, r);
		lens.pb(len[u] + 1);
	}
	sort(all(lens));
	lens.erase(unique(all(lens)), lens.end());
	if (sz(lens) > 2) {
		printf("-1\n");
		return;
	}
	int sum = 0;
	forn(i, sz(lens)) {
		sum += lens[i];
	}
	while (!(sum & 1)) {
		sum = sum >> 1;
	}
	printf("%d\n", sum);
}

int main() {
	ios_base::sync_with_stdio(false);
#ifdef SU2
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	srand((unsigned int)time(NULL));

	cout << setprecision(15) << fixed;

	solve();

#ifdef SU2
	cerr << "time: " << clock() << " ms" << endl;
#endif

	return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>;

const int N=1e6+10;
ll n,u,v,rt,res,d[N];
vector<ll>adj[N];
bool vld;

void dfs(int u,int p)
{
	set<int>s;
	for(int i=0,v;i<adj[u].size();i++)
	{
		v=adj[u][i];
		if(v==p)continue;
		dfs(v,u);
		if(rt!=-1)return;
		s.insert(d[v]);
	}
	if(s.size()>1)rt=u;
	else
	{
		if(s.size()==0)d[u]=0;
		else d[u]=(*s.begin())+1;
	}
}

void dfs2(int u,int p)
{
	set<int>s;
	set<int>::iterator it;
	for(int i=0,v;i<adj[u].size();i++)
	{
		v=adj[u][i];
		if(v==p)continue;
		dfs2(v,u);
		s.insert(d[v]);
	}
	if(u==rt)
	{
		if(s.size()==0)res=1;
		else if(s.size()==1)res=(*s.begin())+1;
		else if(s.size()==2)
		{
			it=s.begin();
			res=(*it)+1;
			it++;
			res+=(*it)+1;
		}
		else vld=0;
	}
	else if(s.size()>1)vld=0;
	else
	{
		if(s.size()==0)d[u]=0;
		else d[u]=(*s.begin())+1;
	}
}

void solve()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	rt=-1;
	dfs(1,-1);
	if(rt==-1)
	{
		res=d[1];
		while(res%2==0)res/=2;
		cout<<res<<"\n";
	}
	else
	{
		vld=1;
		dfs2(rt,-1);
		if(vld)
		{
			while(res%2==0)res/=2;
			cout<<res<<"\n";
		}
		else cout<<"-1\n";
	}

}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>;

const int N=1e6+10;
ll n,u,v,rt,res,d[N];
vector<ll>adj[N];
bool vld;

void dfs(int u,int p)
{
	set<int>s;
	for(int i=0,v;i<adj[u].size();i++)
	{
		v=adj[u][i];
		if(v==p)continue;
		dfs(v,u);
		if(rt!=-1)return;
		s.insert(d[v]);
	}
	if(s.size()>1)rt=u;
	else
	{
		if(s.size()==0)d[u]=0;
		else d[u]=(*s.begin())+1;
	}
}

void dfs2(int u,int p)
{
	set<int>s;
	set<int>::iterator it;
	for(int i=0,v;i<adj[u].size();i++)
	{
		v=adj[u][i];
		if(v==p)continue;
		dfs2(v,u);
		s.insert(d[v]);
	}
	if(u==rt)
	{
		if(s.size()==0)res=1;
		else if(s.size()==1)res=(*s.begin())+1;
		else if(s.size()==2)
		{
			it=s.begin();
			res=(*it)+1;
			it++;
			res+=(*it)+1;
		}
		else vld=0;
	}
	else if(s.size()>1)vld=0;
	else
	{
		if(s.size()==0)d[u]=0;
		else d[u]=(*s.begin())+1;
	}
}

void solve()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	rt=-1;
	dfs(1,-1);
	if(rt==-1)cout<<d[1]<<"\n";
	else
	{
		vld=1;
		dfs2(rt,-1);
		if(vld)cout<<res<<"\n";
		else cout<<"-1\n";
	}

}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}


#include<stdio.h>
#include<vector>
#include<set>
const int maxn=200020;
std::vector<int>edge[maxn];
int N,q;
int read(){
	__asm{
push esi
mov edi,getchar
sta:
call edi
lea ecx,[eax-30h]
cmp cl,9
ja sta
xor esi,esi
whi:
movsx edx,al
xor edx,30h
lea eax,[esi+esi*4]
lea esi,[edx+eax*2]
call edi
lea ecx,[eax-30h]
cmp cl,9
jbe whi
mov eax,esi
pop esi
	}
}
int cut(int t){
	while(!(t&1))t>>=1;
	return t;
}
int dfs(int n,int pre){
	int deg=edge[n].size();
	if(deg==1)return 1;
	else if(deg==2)return 1+dfs((pre==edge[n][0])?edge[n][1]:edge[n][0],n);
	else{
		std::set<int>s;
		for(int i=0;i<deg;i++)if(edge[n][i]!=pre)
			s.insert(dfs(edge[n][i],n));
		if(s.size()==1)return *s.begin()+1;
		if(q)printf("-1\n"),exit(0);
		if(pre)q=1,s.insert(dfs(pre,n));
		if(s.size()>=3)printf("-1\n"),exit(0);
		printf("%d\n",cut(*s.begin()+*s.rbegin()));
		exit(0);
	};
}
int main(){
	N=read();
	for(int i=1;i<N;i++){
		int u=read(),v=read();
		edge[u].push_back(v); edge[v].push_back(u);
	}
	for(int i=1;i<=N;i++)if(edge[i].size()>2)
		dfs(i,0);
	printf("%d",cut(N-1));
	return 0;
}


#include<stdio.h>
#include<vector>
#include<set>
const int maxn=200020;
std::vector<int>edge[maxn];
int N,q;
int read(){
	__asm{
push esi
mov edi,getchar
sta:
call edi
lea ecx,[eax-30h]
cmp cl,9
ja sta
xor esi,esi
whi:
movsx edx,al
xor edx,30h
lea eax,[esi+esi*4]
lea esi,[edx+eax*2]
call edi
lea ecx,[eax-30h]
cmp cl,9
jbe whi
mov eax,esi
pop esi
	}
}
int cut(int t){
	while(!(t&1))t>>=1;
	return t;
}
int dfs(int n,int pre){
	int deg=edge[n].size();
	if(deg==1)return 1;
	else if(deg==2)return 1+dfs((pre==edge[n][0])?edge[n][1]:edge[n][0],n);
	else{
		std::set<int>s;
		for(int i=0;i<deg;i++)if(edge[n][i]!=pre)
			s.insert(dfs(edge[n][i],n));
		if(s.size()==1)return *s.begin()+1;
		if(q)printf("-1\n"),exit(0);
		if(pre)q=1,s.insert(dfs(pre,n));
		if(s.size()>=3)printf("-1\n"),exit(0);
		printf("%d\n",cut(*s.begin()+*s.rbegin()));
		exit(0);
	};
}
int main(){
	N=read();
	for(int i=1;i<N;i++){
		int u=read(),v=read();
		edge[u].push_back(v); edge[v].push_back(u);
	}
	for(int i=1;i<=N;i++)if(edge[i].size()>2)
		return 0*printf("%d",cut(dfs(i,0)));
	printf("%d",cut(N-1));
	return 0;
}


#include<stdio.h>
#include<vector>
#include<set>
const int maxn=100020;
std::vector<int>edge[maxn];
int N,q;
int read(){
	__asm{
push esi
mov edi,getchar
sta:
call edi
lea ecx,[eax-30h]
cmp cl,9
ja sta
xor esi,esi
whi:
movsx edx,al
xor edx,30h
lea eax,[esi+esi*4]
lea esi,[edx+eax*2]
call edi
lea ecx,[eax-30h]
cmp cl,9
jbe whi
mov eax,esi
pop esi
	}
}
int cut(int t){
	while(!(t&1))t>>=1;
	return t;
}
int dfs(int n,int pre){
	int deg=edge[n].size();
	if(deg==1)return 1;
	else if(deg==2)return 1+dfs((pre==edge[n][0])?edge[n][1]:edge[n][0],n);
	else{
		std::set<int>s;
		for(int i=0;i<deg;i++)if(edge[n][i]!=pre)
			s.insert(dfs(edge[n][i],n));
		if(s.size()==1)return *s.begin()+1;
		if(q)printf("-1\n"),exit(0);
		if(pre)q=1,s.insert(dfs(pre,n));
		if(s.size()>=3)printf("-1\n"),exit(0);
		printf("%d\n",cut(*s.begin()+*s.rbegin()));
		exit(0);
	};
}
int main(){
	N=read();
	for(int i=1;i<N;i++){
		int u=read(),v=read();
		edge[u].push_back(v); edge[v].push_back(u);
	}
	for(int i=1;i<=N;i++)if(edge[i].size()>2)
		dfs(i,0);
	printf("%d",cut(N-1));
	return 0;
}


#include<stdio.h>
#include<vector>
#include<set>
const int maxn=200020;
std::vector<int>edge[maxn];
int N,q;
int read(){
	__asm{
push esi
mov edi,getchar
sta:
call edi
lea ecx,[eax-30h]
cmp cl,9
ja sta
xor esi,esi
whi:
movsx edx,al
xor edx,30h
lea eax,[esi+esi*4]
lea esi,[edx+eax*2]
call edi
lea ecx,[eax-30h]
cmp cl,9
jbe whi
mov eax,esi
pop esi
	}
}
int cut(int t){
	while(!(t&1))t>>=1;
	return t;
}
int dfs(int n,int pre){
	int deg=edge[n].size();
	if(deg==1)return 1;
	else if(deg==2)return 1+dfs((pre==edge[n][0])?edge[n][1]:edge[n][0],n);
	else{
		std::set<int>s;
		for(int i=0;i<deg;i++)if(edge[n][i]!=pre)
			s.insert(dfs(edge[n][i],n));
		if(s.size()==1)return *s.begin()+1;
		if(q)printf("-1\n"),exit(0);
		if(pre)q=1,s.insert(dfs(pre,n));
		if(s.size()>=3)printf("-1\n"),exit(0);
		printf("%d\n",cut(*s.begin()+*s.rbegin()));
		exit(0);
	};
}
int main(){
	N=read();
	for(int i=1;i<N;i++){
		int u=read(),v=read();
		edge[u].push_back(v); edge[v].push_back(u);
	}
	for(int i=1;i<=N;i++)if(edge[i].size()>2)
		return 0*printf("%d",cut(dfs(i,0)));
//	printf("%d",cut(N-1));
//	return 0;
}


#include <ios>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

std::vector<int> path;
std::vector<std::vector<int> > adjlist;
std::vector<int> temp_adjlist;
std::set<int> tets;
int mdist[200005] = {};
int par[200005] = {};

int path_length(int x, int parent) //returns path length, or -1 if impossible
{
	if (parent == -1) //can have up to 2 different guys
	{
		for (std::vector<int>::iterator it = adjlist[x].begin(); it != adjlist[x].end(); it++)
		{
			int g = path_length(*it, x);
			if (g == -1)
				return -1;
			else
				tets.insert(g);
		}
		if (tets.size() > 2)
			return -1;
		else
		{
			int sum = 0;
			for (std::set<int>::iterator it = tets.begin(); it != tets.end(); it++)
				sum += *it;
			return sum+1;
		}
	}
	else
	{
		int req = 0;
		for (std::vector<int>::iterator it = adjlist[x].begin(); it != adjlist[x].end() && req != -1; it++)
		{
			if (*it != parent)
			{
				int t = path_length(*it, x);
				if (t == -1)
					req = -1;
				else if (req == 0)
					req = t;
				else if (req != t)
					req = -1;
			}
		}
		if (req == -1)
			return -1;
		else
			return req+1;
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n, a, b;
	std::cin >> n;
	adjlist.resize(n);
	for (int i = 0; i < n-1; i++)
	{
		std::cin >> a >> b;
		a--; b--;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		mdist[i] = -1;
	std::queue<int> bfs;
	bfs.push(0);
	mdist[0] = 0;
	while (!bfs.empty())
	{
		int s = bfs.front();
		for (std::vector<int>::iterator it = adjlist[s].begin(); it != adjlist[s].end(); it++)
		{
			if (mdist[*it] == -1)
			{
				mdist[*it] = mdist[s]+1;
				bfs.push(*it);
			}
		}
		bfs.pop();
	}
	int mx = 0;
	for (int i = 0; i < n; i++)
		if (mdist[mx] < mdist[i])
			mx = i;

	for (int i = 0; i < n; i++)
		mdist[i] = -1;
	for (int i = 0; i < n; i++)
		par[i] = -1;
	bfs.push(mx);
	mdist[mx] = 0;
	while (!bfs.empty())
	{
		int s = bfs.front();
		for (std::vector<int>::iterator it = adjlist[s].begin(); it != adjlist[s].end(); it++)
		{
			if (mdist[*it] == -1)
			{
				par[*it] = s;
				mdist[*it] = mdist[s]+1;
				bfs.push(*it);
			}
		}
		bfs.pop();
	}
	int my = 0;
	for (int i = 0; i < n; i++)
		if (mdist[my] < mdist[i])
			my = i;

	int g = my;
	while (par[g] != -1)
	{
		path.push_back(g);
		g = par[g];
	}
	path.push_back(mx);

	if ((path.size()) & 1) //size is odd: there's one unique root
	{
		int root = path[(path.size())/2];
		int ans = path_length(root, -1);
		if (ans == -1)
			std::cout << -1;
		else
		{
			ans--;
			while (ans % 2 == 0)
				ans /= 2;
			std::cout << ans << '\n';
		}
	}
	else //there are two roots
	{
		int root1 = path[(path.size())/2];
		int root2 = path[(path.size()-1)/2];

		temp_adjlist.clear();
		for (std::vector<int>::iterator it = adjlist[root1].begin(); it != adjlist[root1].end(); it++)
		{
			if (*it != root2)
				temp_adjlist.push_back(*it);
		}
		adjlist[root1] = temp_adjlist;

		temp_adjlist.clear();
		for (std::vector<int>::iterator it = adjlist[root2].begin(); it != adjlist[root2].end(); it++)
		{
			if (*it != root1)
				temp_adjlist.push_back(*it);
		}
		adjlist[root2] = temp_adjlist;

		int ans1 = path_length(root1, root2);
		int ans2 = path_length(root2, root1);

		if (ans1 == -1 || ans2 == -1)
			std::cout << -1 << '\n';
		else
		{
			int ans = ans1 + ans2;
			ans--;
			while (ans % 2 == 0)
				ans /= 2;
			std::cout << ans << '\n';
		}
	}
}


#include <ios>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

std::vector<int> path;
std::vector<std::vector<int> > adjlist;
std::vector<int> temp_adjlist;
std::set<int> tets;
int mdist[100005] = {};
int par[100005] = {};

int path_length(int x, int parent) //returns path length, or -1 if impossible
{
	if (parent == -1) //can have up to 2 different guys
	{
		for (std::vector<int>::iterator it = adjlist[x].begin(); it != adjlist[x].end(); it++)
		{
			int g = path_length(*it, x);
			if (g == -1)
				return -1;
			else
				tets.insert(g);
		}
		if (tets.size() > 2)
			return -1;
		else
		{
			int sum = 0;
			for (std::set<int>::iterator it = tets.begin(); it != tets.end(); it++)
				sum += *it;
			return sum+1;
		}
	}
	else
	{
		int req = 0;
		for (std::vector<int>::iterator it = adjlist[x].begin(); it != adjlist[x].end() && req != -1; it++)
		{
			if (*it != parent)
			{
				int t = path_length(*it, x);
				if (t == -1)
					req = -1;
				else if (req == 0)
					req = t;
				else if (req != t)
					req = -1;
			}
		}
		if (req == -1)
			return -1;
		else
			return req+1;
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n, a, b;
	std::cin >> n;
	adjlist.resize(n);
	for (int i = 0; i < n-1; i++)
	{
		std::cin >> a >> b;
		a--; b--;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		mdist[i] = -1;
	std::queue<int> bfs;
	bfs.push(0);
	mdist[0] = 0;
	while (!bfs.empty())
	{
		int s = bfs.front();
		for (std::vector<int>::iterator it = adjlist[s].begin(); it != adjlist[s].end(); it++)
		{
			if (mdist[*it] == -1)
			{
				mdist[*it] = mdist[s]+1;
				bfs.push(*it);
			}
		}
		bfs.pop();
	}
	int mx = 0;
	for (int i = 0; i < n; i++)
		if (mdist[mx] < mdist[i])
			mx = i;

	for (int i = 0; i < n; i++)
		mdist[i] = -1;
	for (int i = 0; i < n; i++)
		par[i] = -1;
	bfs.push(mx);
	mdist[mx] = 0;
	while (!bfs.empty())
	{
		int s = bfs.front();
		for (std::vector<int>::iterator it = adjlist[s].begin(); it != adjlist[s].end(); it++)
		{
			if (mdist[*it] == -1)
			{
				par[*it] = s;
				mdist[*it] = mdist[s]+1;
				bfs.push(*it);
			}
		}
		bfs.pop();
	}
	int my = 0;
	for (int i = 0; i < n; i++)
		if (mdist[my] < mdist[i])
			my = i;

	int g = my;
	while (par[g] != -1)
	{
		path.push_back(g);
		g = par[g];
	}
	path.push_back(mx);

	if ((path.size()) & 1) //size is odd: there's one unique root
	{
		int root = path[(path.size())/2];
		int ans = path_length(root, -1);
		if (ans == -1)
			std::cout << -1;
		else
		{
			ans--;
			while (ans % 2 == 0)
				ans /= 2;
			std::cout << ans << '\n';
		}
	}
	else //there are two roots
	{
		int root1 = path[(path.size())/2];
		int root2 = path[(path.size()-1)/2];

		temp_adjlist.clear();
		for (std::vector<int>::iterator it = adjlist[root1].begin(); it != adjlist[root1].end(); it++)
		{
			if (*it != root2)
				temp_adjlist.push_back(*it);
		}
		adjlist[root1] = temp_adjlist;

		temp_adjlist.clear();
		for (std::vector<int>::iterator it = adjlist[root2].begin(); it != adjlist[root2].end(); it++)
		{
			if (*it != root1)
				temp_adjlist.push_back(*it);
		}
		adjlist[root2] = temp_adjlist;

		int ans1 = path_length(root1, root2);
		int ans2 = path_length(root2, root1);

		if (ans1 == -1 || ans2 == -1)
			std::cout << -1 << '\n';
		else
		{
			int ans = ans1 + ans2;
			ans--;
			while (ans % 2 == 0)
				ans /= 2;
			std::cout << ans << '\n';
		}
	}
}


#pragma comment(linker, "/STACK:216000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <set>
#include <bitset>
#include <sstream>
#include <array>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const ll MAX = numeric_limits<ll>::max();
const ll MIN = numeric_limits<ll>::min();
const double PI = 3.1415926535;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& out, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << endl;
	return out;
}

template<class T>
istream& operator>>(istream& in, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i)
		in >> v[i];
	return in;
}

template<class R, class L>
istream& operator>>(istream& in, pair<R, L>& p) {
	in >> p.first >> p.second;
	return in;
}

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

ll ceil(ll a, ll b) {
	if (a % b)
		return a / b + 1;
	return a / b;
}

ll mod(ll a, ll b) {
	return (a % b + b) % b;
}

ll inv_by_mod(ll x, ll m) {
	if (x == 0)
		return 1;
	ll ans = 1;
	ll cur = x;
	ll pow = m - 2;
	while (pow > 0) {
		if (pow & 1)
			ans = mod(ans * cur, m);
		pow >>= 1;
		cur = mod(cur * cur, m);

	}
	return ans;
}

bool dfs1(int v, vector<set<int>> &G, vector<bool>& used, vector<int>& d) {
	used[v] = true;
	set<int> len;
	vector<int> child;
	for (auto it = G[v].begin(); it != G[v].end(); ++it) {
		child.push_back(*it);
	}
	for (int i = 0; i < child.size(); ++i) {
		if (!used[child[i]]) {
			bool straight = dfs1(child[i], G, used, d);
			if (!straight) {
				len.insert(-1);
				continue;
			}
			int cur_len = d[child[i]] + 1;
			if (len.find(cur_len) == len.end()) {
				len.insert(cur_len);
			}
			else {
				G[v].erase(child[i]);
			}
		}
	}
	if (len.find(-1) != len.end()) {
		d[v] = -1;
		return false;
	}
	if (len.size() == 0) {
		d[v] = 0;
		return true;
	}
	else if (len.size() == 1) {
		d[v] = *len.begin();
		return true;
	}
	d[v] = -1;
	return false;
}

int dfs2(int v, int prev_len, vector<set<int>> &G, vector<bool>& used, vector<int>& d) {
	used[v] = true;
	if (d[v] != -1)
		return d[v];

	if (G[v].size() > 3)
		return -1;

	if (G[v].size() == 1 || G[v].size() == 2) {
		for (auto it = G[v].begin(); it != G[v].end(); ++it) {
			if (!used[*it]) {
				return dfs2(*it, prev_len + 1, G, used, d);
			}
		}
	}
	// size == 3
	vector<int> ch;
	for (auto it = G[v].begin(); it != G[v].end(); ++it) {
		if (!used[*it])
			ch.push_back(*it);
	}
	if (d[ch[0]] != -1 && d[ch[1]] != -1) {
		if (d[ch[0]] == prev_len - 1 || d[ch[1]] == prev_len - 1)
			return d[ch[0]] + d[ch[1]] + 2;
	}
	if (d[ch[0]] == prev_len - 1 && d[ch[1]] == -1) {
		return dfs2(ch[1], prev_len + 1, G, used, d);
	}
	if (d[ch[1]] == prev_len - 1 && d[ch[0]] == -1) {
		return dfs2(ch[0], prev_len + 1, G, used, d);
	}
	return -1;
}

int main() {
	ios_base::sync_with_stdio(false);
#ifdef DEBUG
	ifstream cin{ "input.txt" };
	ofstream cout{ "output.txt" };
#endif
	int n;
	cin >> n;
	vector<set<int>> G(n);
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		G[u].insert(v);
		G[v].insert(u);
	}
	int leaf = 0;
	for (int i = 0; i < n; ++i) {
		if (G[i].size() == 1)
			leaf = i;
	}

	vector<bool> used(n, false);
	vector<int> d(n);
	dfs1(leaf, G, used, d);
	used = vector<bool>(n, false);
	int len = dfs2(leaf, 0, G, used, d);
	while (len % 2 == 0) {
		len = len / 2;
	}
	cout << len;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include<map>
#include <string>
#include <algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N = 2e5 + 2;
int n, x, y, p[N];
vector<int>v[N];
int node, mx;
void DFS(int src, int par, int dep = 0){
	if (dep > mx){
		mx = dep;
		node = src;
	}
	p[src] = par;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		if (nxt == par)
			continue;
		DFS(nxt, src, dep + 1);
	}
}
bool fail;
int root, r2, sum;
set<int>s1, s2;
int fix(int src, int par){
	set<int>s;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		if (nxt == par)
			continue;
		int len = fix(nxt, src) + 1;
		if (!s.insert(len).second)
			sum += len;
	}
	//cout << src << " " << s.size() << endl;
	if (mx % 2 == 0){
		if (src != root && s.size() > 1)
			fail |= 1;
		else if (src == root)
			fail |= s.size() > 2;

	}
	else{
		if (src == root)
			s1 = s;
		else if (src == r2)
			s2 = s;
		else if(s.size() > 1)
			fail |= 1;
	}
	if (!s.size())
		return 0;
	return *(s.begin());
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; ++i){
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	DFS(1, -1);
	mx = 0;
	int S = node;
	DFS(node, -1);
	int E = node;
	root = E;
	int M = mx / 2;
	while (M--)
		root = p[root];
	r2 = p[root];
	fix(root, -1);
	if (mx % 2 == 1){
		if (s1.size() > 2 || s2.size() > 2)
			fail = 1;
		else{
			int v1 = *s2.begin();
			int v2 = -100;
			if (s2.size() != 1)
				v2 = *++s2.begin();
			if (n != 2 && s1.find(v1 - 1) != s1.end())
				sum += v1;
			if (n != 2 && s1.find(v2 - 1) != s1.end())
				sum += v2;
		}
	}
	if (fail)
		puts("-1");
	else
		cout << n - 1 - sum << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include<map>
#include <string>
#include <algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N = 2e5 + 2;
int n, x, y, p[N];
vector<int>v[N];
int node, mx;
void DFS(int src, int par, int dep = 0){
	if (dep > mx){
		mx = dep;
		node = src;
	}
	p[src] = par;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		if (nxt == par)
			continue;
		DFS(nxt, src, dep + 1);
	}
}
bool fail;
int root, sum;
int fix(int src, int par){
	set<int>s;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		if (nxt == par)
			continue;
		int len = fix(nxt, src) + 1;
		if (!s.insert(len).second)
			sum += len;
	}
	//cout << src << " " << s.size() << endl;
	if (src != root && s.size() > 1)
		fail |= 1;
	else if (src == root){

		fail |= s.size() > 2;
	}
	if (!s.size())
		return 0;
	return *(s.begin());
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; ++i){
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	DFS(1, -1);
	mx = 0;
	int S = node;
	DFS(node, -1);
	int E = node;
	root = E;
	int M = mx / 2;
	while (M--)
		root = p[root];
	fix(root, -1);
	if (fail)
		puts("-1");
	else
		cout << n - 1 - sum << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include<map>
#include <string>
#include <algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N = 2e5 + 2;
int n, x, y, p[N];
vector<int>v[N];
int node, mx;
void DFS(int src, int par, int dep = 0){
	if (dep > mx){
		mx = dep;
		node = src;
	}
	p[src] = par;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		if (nxt == par)
			continue;
		DFS(nxt, src, dep + 1);
	}
}
bool fail;
int root, sum;
int fix(int src, int par){
	set<int>s;
	for (int i = 0; i < v[src].size(); ++i){
		int nxt = v[src][i];
		//if (src == 9)
			//cout << nxt << endl;
		if (nxt == par)
			continue;
		int len = fix(nxt, src) + 1;

		if (!s.insert(len).second)
			sum += len;
		//if (src == 9)
			//cout << nxt << " " << len << endl;
	}
	//cout << src << " " << s.size() << endl;
	if (src != root && s.size() > 1)
		fail |= 1;
	else if (src == root){

		fail |= s.size() > 2;
	}
	if (!s.size())
		return 0;
	return *(s.begin());
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; ++i){
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	DFS(1, -1);
	mx = 0;
	int S = node;
	DFS(node, -1);
	int E = node;
	root = E;
	int M = mx / 2;
	while (M--)
		root = p[root];
	fix(root, -1);
	int sol = n - 1 - sum;
	while (sol % 2 == 0)
		sol /= 2;
	if (fail)
		puts("-1");
	else
		cout << sol << endl;

	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <list>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define setzero(arr) memset(arr, 0, sizeof(arr))

#define fi(i, from, to) for(int i = (from); i < (to); i++)
#define fri(i, from, to) for(int i = (from); i >= (to); i--)
#define fa(it, col) for(auto (it) = (col).begin(); (it) != (col).end(); (it)++)
#define fra(it, col) for(auto (it) = (col).rbegin(); (it) != (col).rend(); (it)++)
#define getBit(vv, bit) ((vv & (lol)(1LL << (31 - bit))) == 0LL ? 0 : 1)
#define getBit64(vv, bit) ((vv & (lol)(1LL << (63 - bit))) == 0LL ? 0 : 1)
#define allFrom(obj) obj.begin(), obj.end()
#define MOD 1000000007
#define PI 3.14159265
#define INF 10000000

typedef unsigned long long lol;
typedef  long long slol;
using namespace std;

vector<int> vtx[201000];
bool visited[201000];
bool err = false;

int dfs(int v, int d = 0) {
	if (visited[v] || err)
		return 0;
	visited[v] = true;

	int res = 0;
	set<int> ss;
	fa(it, vtx[v]) {
		if (visited[*it])
			continue;
		ss.insert( dfs(*it, d + 1));
	}

	if (ss.size() == 1) {
		return *ss.begin() + 1;
	}

	ss.erase(d);
	if (ss.size() == 0)
		return 1;

	if (ss.size() > 1) {
		err = true;
		return 1;
	}

	return *ss.rbegin() + 1;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d ", &n);
	fi(i, 0, n - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--, b--;
		vtx[a].push_back(b);
		vtx[b].push_back(a);
	}

	setzero(visited);
	fi(i, 0, n) {
		if (vtx[i].size() != 1)
			continue;
		int rlen = dfs(i, 0);
		if (err) {
			printf("-1");
			return 0;
		}

		while (rlen > 1 && rlen % 2 == 1)
			rlen = (rlen - 1) / 2 + 1;

		printf("%d", rlen - 1);
		return 0;

	}

	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <list>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define setzero(arr) memset(arr, 0, sizeof(arr))

#define fi(i, from, to) for(int i = (from); i < (to); i++)
#define fri(i, from, to) for(int i = (from); i >= (to); i--)
#define fa(it, col) for(auto (it) = (col).begin(); (it) != (col).end(); (it)++)
#define fra(it, col) for(auto (it) = (col).rbegin(); (it) != (col).rend(); (it)++)
#define getBit(vv, bit) ((vv & (lol)(1LL << (31 - bit))) == 0LL ? 0 : 1)
#define getBit64(vv, bit) ((vv & (lol)(1LL << (63 - bit))) == 0LL ? 0 : 1)
#define allFrom(obj) obj.begin(), obj.end()
#define MOD 1000000007
#define PI 3.14159265
#define INF 10000000

typedef unsigned long long lol;
typedef  long long slol;
using namespace std;

vector<int> vtx[201000];
bool visited[201000];
bool err = false;

int dfs(int v, int d = 0) {
	if (visited[v] || err)
		return 0;
	visited[v] = true;

	int res = 0;
	set<int> ss;
	fa(it, vtx[v]) {
		if (visited[*it])
			continue;
		ss.insert( dfs(*it, d + 1));
	}

	if (ss.size() == 1) {
		return *ss.begin() + 1;
	}

	ss.erase(d);
	if (ss.size() == 0)
		return 1;

	if (ss.size() > 1) {
		err = true;
		return 1;
	}

	return *ss.rbegin() + 1;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d ", &n);
	fi(i, 0, n - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--, b--;
		vtx[a].push_back(b);
		vtx[b].push_back(a);
	}

	setzero(visited);
	fi(i, 0, n) {
		if (vtx[i].size() != 1)
			continue;
		int rlen = dfs(i, 0);
		if (err) {
			printf("-1");
			return 0;
		}

		while (rlen > 1 && rlen % 2 == 1)
			rlen = (rlen - 1) / 2;

		printf("%d", rlen - 1);
		return 0;

	}

	return 0;
}


#include "iostream"
#include "cstdio"
#include "math.h"
#include "algorithm"
#include "string"
#include "string.h"
#include "vector"
#include "map"
#include "queue"
#include "bitset"
#include "set"
#include "fstream"
#include "time.h"
using namespace std;
const int inf = 0x3f3f3f3f;
vector<int> edge[200200], last;
int root, treedep, n;
bool flag;
struct Node {
	int from, dep;
}node[200020];

void caldep(int x, int fa)
{
	int len = edge[x].size();
	for (int i = 0;i<len;i++){
		if (edge[x][i] == fa)
			continue;
		int next = edge[x][i];
		node[next].dep = node[x].dep + 1;
		node[next].from = x;
		if (node[next].dep>treedep){
			treedep = node[next].dep;
			root = next;
		}
		caldep(next, x);
	}
}

int dfs(int x, int fa)
{
	if (flag)
		return 0;
	int minnode = inf, maxnode = -1, len = edge[x].size();
	for (int i = 0;i<len;i++){
		if (edge[x][i] == fa)
			continue;
		int next = edge[x][i];
		int num = dfs(next, x);
		if (flag)
			return 0;
		minnode = min(minnode, num);
		maxnode = max(maxnode, num);
		if (fa == -1)
			last.push_back(num);
	}
	if (maxnode == -1)
		return 1;    //only this point
	if (fa == -1) {
		int siz = last.size();
		for (int i = 0;i<siz;i++) {
			if (last[i] != minnode && last[i] != maxnode) {
				flag = true;
				return 0;
			}
		}
		return maxnode + minnode + 1;
	}
	else{
		if (minnode == maxnode)
			return maxnode + 1;  //cut until left maxnode+1 points
		else{
			flag = true;
			return 0;
		}
	}
}
void buildtree() {
	node[1].from = -1;node[1].dep = 0;
	treedep = -1;
	caldep(1, -1);

	node[root].from = -1;node[root].dep = 0;
	treedep = -1;
	caldep(root, -1);

	for (int i = 0;i<treedep / 2;i++)
		root = node[root].from;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0;i<n-1;i++){
		int u, v;
		scanf("%d %d", &u, &v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	buildtree();
	flag=false;
	int ans = dfs(root, -1);

	if (flag)
		puts("-1");
	else{
		for (;;ans = ans / 2 + 1) {
			if (ans % 2 == 0) {
				printf("%d\n", ans - 1);
				break;
			}
		}
	}
	return 0;
}


#include "iostream"
#include "cstdio"
#include "math.h"
#include "algorithm"
#include "string"
#include "string.h"
#include "vector"
#include "map"
#include "queue"
#include "bitset"
#include "set"
#include "fstream"
#include "time.h"
using namespace std;
const int inf = 0x3f3f3f3f;
vector<int> edge[200200], last;
int root, treedep, n;
bool flag;
struct Node {
	int from, dep;
}node[200020];

void caldep(int x, int fa)
{
	int len = edge[x].size();
	for (int i = 0;i<len;i++){
		if (edge[x][i] == fa)
			continue;
		int next = edge[x][i];
		node[next].dep = node[x].dep + 1;
		node[next].from = x;
		if (node[next].dep>treedep){
			treedep = node[next].dep;
			root = next;
		}
		caldep(next, x);
	}
}

int dfs(int x, int fa)
{
	if (flag)
		return 0;
	int minnode = inf, maxnode = -1, len = edge[x].size();
	for (int i = 0;i<len;i++){
		if (edge[x][i] == fa)
			continue;
		int next = edge[x][i];
		int num = dfs(next, x);
		if (flag)
			return 0;
		minnode = min(minnode, num);
		maxnode = max(maxnode, num);
		if (fa == -1)
			last.push_back(num);
	}
	if (len == 0)
		return 1;    //only this point
	if (fa == 1) {
		int siz = last.size();
		for (int i = 0;i<siz;i++) {
			if (last[i] != minnode && last[i] != maxnode) {
				flag = true;
				return 0;
			}
		}
		return maxnode + minnode + 1; //end
	}
	else{
		if (minnode == maxnode)
			return maxnode + 1;  //cut until left maxnode+1 points
		else{
			flag = true;
			return 0;
		}
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0;i < n - 1;i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	node[1].from = -1;
	node[1].dep = 0;
	treedep = -1;
	caldep(1, -1);

	node[root].from = -1;
	node[root].dep = 0;
	treedep = -1;
	caldep(root, -1);

	for (int i = 0;i<treedep / 2;i++)
		root = node[root].from;

	flag=false;
	int ans = dfs(root, -1);

	if (flag)
		puts("-1");
	else{
		for (;;ans = ans / 2 + 1) {
			if (ans % 2 == 0) {
				printf("%d\n", ans - 1);
				break;
			}
		}
	}
	return 0;
}


#include<cstdio>
#include<set>
using namespace std;
struct arr
  {
   int aa,bb;
  }na[400010];
int n,nn,s,x,y,root,head[200010];
void add(int x,int y)
  {
   nn=nn+1;na[nn].aa=y;na[nn].bb=head[x];head[x]=nn;
  }
int dfs(int u,int k)
  {
   set<int>T;
   for (int i=head[u];i;i=na[i].bb)
     {
      int j=na[i].aa;
      if (j==k) continue;
      int sum=dfs(j,u);
	  if (sum==-1) return -1;
	  if (sum!=-1) T.insert(sum+1);
	 }
   if (T.size()==0) return 0;
   if (T.size()==1) return *T.begin();
   if ((T.size()==2) && (k==0)) return *T.begin()+*T.rbegin();
   root=u;
   return -1;
  }
int main()
  {
   scanf("%d",&n);
   for (int i=1;i<=n-1;i++)
     {
      scanf("%d%d",&x,&y);
      add(x,y);add(y,x);
	 }
   root=1;
   s=dfs(1,0);
   if ((s==-1) && (root!=1)) s=dfs(root,0);
   while (s%2==0) s=s/2;
   printf("%d\n",s);
   return 0;
  }


#include <iostream>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <string>
using namespace std;

int n;
vector<int> adj[200200];
int a,b;

int dist[200200];
int dist2[200200];
void dfs(int nd,int p,int d){
	dist[nd]=max(dist[nd],d);
	for(int i=0;i<adj[nd].size();i++){
		int ch=adj[nd][i];
		if(ch==p)continue;
		dfs(ch,nd,d+1);
	}
}

void dfs2(int nd,int p,int d){
	dist2[nd]=max(dist2[nd],d);
	for(int i=0;i<adj[nd].size();i++){
		int ch=adj[nd][i];
		if(ch==p)continue;
		dfs2(ch,nd,d+1);
	}
}

int dfs_ans(int nd,int p){
	int h=-1;
	for(int i=0;i<adj[nd].size();i++){
		int ch=adj[nd][i];
		if(ch==p)continue;
		int g=dfs_ans(ch,nd);
		if(g==-1)return -1;
		if(h==-1){
			h=g;
		} else {
			if(h!=g){
				return -1;
			}
		}
	}
	if(h==-1){
		return 1;
	}
	return h+1;
}
int main(){
	freopen("out.txt","w",stdout);
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);

	}

	int dia_a=1,dia_b;
	int dia;
	dfs(1,1,0);
	for(int i=1;i<=n;i++){
		if(dist[dia_a] < dist[i]){
			dia_a=i;
		}
	}
	for(int i=1;i<=n;i++){
		dist[i]=0;
	}
	dfs(dia_a,dia_a,0);
	dia_b=dia_a;
	for(int i=1;i<=n;i++){
		if(dist[dia_b] < dist[i]){
			dia_b=i;
		}
	}
	for(int i=1;i<=n;i++){
		dist[i]=0;
		dist2[i]=0;
	}
	dfs(dia_a,dia_a,0);
	dfs2(dia_b,dia_b,0);
	dia=dist[dia_b];
	if(dia%2==0){
		int center=-1;
		for(int i=1;i<=n;i++){
			if(dist[i]==dia/2 && dist2[i]==dia/2){
				if(center!=-1){
					assert(false);
				}
				center=i;
			}
		}
		int sol[3];
		sol[0]=sol[1]=sol[2]=-1;
		for(int i=0;i<adj[center].size();i++){
			int ch=adj[center][i];
			int y=dfs_ans(ch,center);
			if(y==-1){
				cout<<-1<<endl;
				return 0;
			}
			if(y != sol[1] && y != sol[2]){
				sol[0]=y;
				sort(sol,sol+3);
			}

		}
		if(sol[0]!=-1){
			cout<<-1<<endl;
				return 0;
		}
		if(sol[1]==-1){
			cout<<sol[2]<<endl;
			return 0;
		} else {
			cout<<sol[2]+sol[1]<<endl;
		}
	}  else {
		int c1=-1,c2=-1;
		for(int i=1;i<=n;i++){
			if(dist[i] == dia/2 && dist2[i] == (dia+1)/2){
				if(c1==-1){
					c1=i;
				} else if(c2==-1){
					c2=i;
				} else {
					assert(false);
				}
			} else if(dist2[i] == dia/2 && dist[i] == (dia+1)/2) {
				if(c1==-1){
					c1=i;
				} else if(c2==-1){
					c2=i;
				} else {
					assert(false);
				}
			}
		}

		int y=dfs_ans(c1,c2);
		int yy=dfs_ans(c2,c1);
		if(y==-1 || yy==-1){
			cout<<-1<<endl;
			return 0;
		} else {
			cout<<dia<<endl;
			return 0;
		}
	}

}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
bitset<3000> b[3000];
struct{double x,y;}a[3000];
struct rec{int x,y;double z;}f[5000010];
int n,m,i,j;

double dist(int i,int j)
{
    return (a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
}

bool operator <(rec a,rec b)
{
    return a.z<b.z;
}

int main()
{
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i].x>>a[i].y;
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++) f[++m].x=i,f[m].y=j,f[m].z=sqrt(dist(i,j))/2;
    sort(f+1,f+m+1);
    for(i=m;i;i--)
    {
        if((b[f[i].x]&b[f[i].y])!=0) break;
        b[f[i].x][f[i].y]=1;
        b[f[i].y][f[i].x]=1;
    }
    cout<<setprecision(10)<<fixed<<f[i].z<<endl;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
bitset<3002> B[3001];
struct connect
{
    int f,t;
    double dis;
}edge[5000000];
struct node
{
    int x,y;
}a[3005];
double cal(int i,int j)
{
    return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
bool cmp(connect a,connect b)
{
    return b.dis<a.dis;
}
int main()
{
    int n;
    scanf("%d",&n);

        for(int i=0;i<n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
        int num=0;
        for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        {
            edge[num].f=i;
            edge[num].t=j;
            edge[num++].dis=cal(i,j)/2.0;
        }
        sort(edge,edge+num,cmp);
        int ans;
        //for(int i=0;i<=3000;i++)
        //B[i].reset();
        for(int i=0;i<num;i++)
        {
            if((B[edge[i].f]&B[edge[i].t])!=0) {ans=i;break;}
            B[edge[i].f][edge[i].t]=1;
            B[edge[i].t][edge[i].f]=1;
        }
        printf("%.10lf\n",edge[ans].dis);

    return 0;
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
bitset<3000> b[3000];
struct{double x,y;}a[3000];
struct rec{int x,y;double z;}f[5000010];
int n,m,i,j;

double dist(int i,int j)
{
    return (a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
}

bool cmp(rec a,rec b)
{
    return a.z<b.z;
}

int main()
{
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i].x>>a[i].y;
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++) f[++m].x=i,f[m].y=j,f[m].z=sqrt(dist(i,j))/2;
    sort(f+1,f+m+1,cmp);
    for(i=m;i;i--)
    {
        if((b[f[i].x]&b[f[i].y])!=0) break;
        b[f[i].x][f[i].y]=1;
        b[f[i].y][f[i].x]=1;
    }
    cout<<setprecision(10)<<fixed<<f[i].z<<endl;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
bitset<3002> B[3001];
struct connect
{
    int f,t;
    double dis;
}edge[5000000];
struct node
{
    int x,y;
}a[3005];
double cal(int i,int j)
{
    return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
bool operator < (connect a,connect b)
{
    return a.dis>b.dis;
}
int main()
{
    int n;
    scanf("%d",&n);

        for(int i=0;i<n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
        int num=0;
        for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        {
            edge[num].f=i;
            edge[num].t=j;
            edge[num++].dis=cal(i,j)/2.0;
        }
        sort(edge,edge+num);
        int ans;
        //for(int i=0;i<=3000;i++)
        //B[i].reset();
        for(int i=0;i<num;i++)
        {
            if((B[edge[i].f]&B[edge[i].t])!=0) {ans=i;break;}
            B[edge[i].f][edge[i].t]=1;
            B[edge[i].t][edge[i].f]=1;
        }
        printf("%.8lf\n",edge[ans].dis);

    return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)/2;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	long double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",(double)x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)/2;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)/2;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	long double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.20Lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		vector<int>ot;
		for(int i=0;i<pun.size();i++)
		{
			if(odl(pun[r],pun[i])<c) continue;
			while(ot.size()>=2 &&  pun[i]!=pun[ot.back()] && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0 && pun[ot[ot.size()-2]]!=pun[i]) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		pun.push_back(make_pair(x,y));
	}
	sort(pun.begin(),pun.end());
	for(int i=static_cast<int>(pun.size())-1;i>=0;i--) pun.push_back(pun[i]);
	ll a=0LL,b=1e8,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)/2;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	long double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10Lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

#define deb(a)

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		deb( printf("   start(%d,%d)\n",f[r].first,f[r].second); )
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		deb( printf("      "); for(int i=0;i<pun.size();i++) printf("[%d,%d]",pun[i].first,pun[i].second); printf("\n"); )
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		deb( printf("      "); for(int i=0;i<pun.size();i++) printf("[%d,%d]",pun[i].first,pun[i].second); printf("\n"); )
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>0) ot.pop_back();
			ot.push_back(i);
		}
		deb( printf("         "); for(int i=0;i<ot.size();i++) printf("[%d,%d] ",pun[ot[i]].first,pun[ot[i]].second); printf("\n"); )
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
		deb( printf("      wyn=%lld\n",wyn); )
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		deb( printf("%lld %lld %lld\n",a,b,c); )
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	deb( printf("a=%lld\n",a); )
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		vector<int>ot;
		for(int i=0;i<pun.size();i++)
		{
			if(odl(pun[r],pun[i])<c) continue;
			while(ot.size()>=2 &&  pun[i]!=pun[ot.back()] && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0 && pun[ot[ot.size()-2]]!=pun[i]) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		pun.push_back(make_pair(x,y));
	}
	sort(pun.begin(),pun.end());
	for(int i=static_cast<int>(pun.size())-1;i>=0;i--) pun.push_back(pun[i]);
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		vector<int>ot;
		for(int i=0;i<pun.size();i++)
		{
			if(odl(pun[r],pun[i])<c) continue;
			while(ot.size()>=2 &&  pun[i]!=pun[ot.back()] && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0 && pun[ot[ot.size()-2]]!=pun[i]) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		pun.push_back(make_pair(x,y));
	}
	sort(pun.begin(),pun.end());
	for(int i=static_cast<int>(pun.size())-1;i>=0;i--) pun.push_back(pun[i]);
	ll a=0LL,b=1e9,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

#define deb(a)

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

vector<pair<int,int> >f;

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		deb( printf("   start(%d,%d)\n",f[r].first,f[r].second); )
		pun.clear();
		for(int j=0;j<n;j++) if(odl(f[r],f[j])>=c) pun.push_back(f[j]);
		if(pun.size()<3)
		{
			if(pun.size()==2) wyn=max(wyn,odl(pun[0],pun[1]));
			continue;
		}
		deb( printf("      "); for(int i=0;i<pun.size();i++) printf("[%d,%d]",pun[i].first,pun[i].second); printf("\n"); )
		for(int i=static_cast<int>(pun.size())-2;i>0;i--) pun.push_back(pun[i]);
		deb( printf("      "); for(int i=0;i<pun.size();i++) printf("[%d,%d]",pun[i].first,pun[i].second); printf("\n"); )
		vector<int>ot;
		ot.push_back(0); ot.push_back(1);
		for(int i=2;i<pun.size();i++)
		{
			while(ot.size()>=2 && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0 && pun[ot[ot.size()-2]]!=pun[i]) ot.pop_back();
			ot.push_back(i);
		}
		deb( printf("         "); for(int i=0;i<ot.size();i++) printf("[%d,%d] ",pun[ot[i]].first,pun[ot[i]].second); printf("\n"); )
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
		deb( printf("      wyn=%lld\n",wyn); )
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f.push_back(make_pair(x,y));
	}
	sort(f.begin(),f.end());
	ll a=0LL,b=1e12,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		deb( printf("%lld %lld %lld\n",a,b,c); )
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	deb( printf("a=%lld\n",a); )
	printf("%.10lf\n",x/2);
	return 0;
}


#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int n;

inline ll ilwek(int ax,int ay,int bx,int by) { return static_cast<ll>(ax)*by-static_cast<ll>(ay)*bx; }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy) { return ilwek(bx-ax,by-ay,cx-ax,cy-ay); }
inline ll ilwek(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { return ilwek(bx-ax,by-ay,dx-cx,dy-cy); }
inline ll ilwek(pair<int,int>a,pair<int,int>b) { return ilwek(a.first,a.second,b.first,b.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second); }
inline ll ilwek(pair<int,int>a,pair<int,int>b,pair<int,int>c,pair<int,int>d) { return ilwek(a.first,a.second,b.first,b.second,c.first,c.second,d.first,d.second); }

vector<pair<int,int> >pun;

inline ll odl(int ax,int ay,int bx,int by) { return static_cast<ll>(ax-bx)*(ax-bx)+static_cast<ll>(ay-by)*(ay-by); }
inline ll odl(pair<int,int>a,pair<int,int>b) { return odl(a.first,a.second,b.first,b.second); }
inline ll odl(int a,int b) { return odl(pun[a],pun[b]); }

ll licz(ll c)
{
	ll wyn=0LL;
	for(int r=0;r<n;r++)
	{
		vector<int>ot;
		for(int i=0;i<pun.size();i++)
		{
			if(odl(pun[r],pun[i])<c) continue;
			while(ot.size()>=2 &&  pun[i]!=pun[ot.back()] && ilwek(pun[ot[ot.size()-2]],pun[ot.back()],pun[ot.back()],pun[i])>=0 && pun[ot[ot.size()-2]]!=pun[i]) ot.pop_back();
			ot.push_back(i);
		}
		int m=ot.size();
		int w=1;
		for(int i=0;i<ot.size();i++)
		{
			while(ilwek(pun[ot[i]],pun[ot[(i+m-1)%m]],pun[ot[w]],pun[ot[(w+1)%m]])>0) w=(w+1)%m;
			wyn=max(wyn,max(odl(ot[i],ot[w]),odl(ot[i],ot[(w+1)%m])));
		}
	}
	return wyn;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		pun.push_back(make_pair(x,y));
	}
	sort(pun.begin(),pun.end());
	for(int i=static_cast<int>(pun.size())-1;i>=0;i--) pun.push_back(pun[i]);
	ll a=0LL,b=1e8,c;
	while(a<b)
	{
		c=(a+b+1)>>1;
		if(c<=licz(c)) a=c;
		else b=c-1;
	}
	double x=0,y=a,z;
	for(int i=0;i<40;i++)
	{
		z=(x+y)/2;
		if(z*z<a) x=z;
		else y=z;
	}
	printf("%.10lf\n",x/2);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
const int lim=1000000000;
struct data{
	int x,y;
}a[3011];
bitset<3011> w[3011];
int ans,i,j,k,n,m,dis[3011][3011],q[3011*3011/2+1];
bool check(int x){
	int i,j;
	for (i=1;i<n;i++)
	 for (j=i+1;j<=n;j++)
	  if (dis[i][j]>=x) w[i][j]=w[j][i]=1;else w[i][j]=w[j][i]=0;
	for (i=1;i<n;i++)
	 for (j=i+1;j<=n;j++)
	  if (dis[i][j]>=x)
	   if ((w[i]&w[j]).any()) return 1;
	return 0;
}
int solve(){
	int l,r,m;
	for (l=1,r=q[0];l<r-1;){
		m=(l+r)>>1;
		if (check(q[m])) l=m;else r=m-1;
	}
	return (check(q[r]))?q[r]:q[l];
}
int sqr(int x){
	return x*x;
}
int main(){
	scanf("%d",&n);q[0]=0;
	for (i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
	for (i=1;i<=n;i++)
	 for (j=i;j<=n;j++) dis[i][j]=dis[j][i]=sqr(a[i].x-a[j].x)+sqr(a[i].y-a[j].y),q[++q[0]]=dis[i][j];
	sort(q+1,q+1+q[0]);
	ans=solve();
	printf("%.9lf\n",sqrt(ans)/2);
	return 0;
}