10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
 10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
 4
4 1
4 3
4 2
 3
3 1
1 2
 9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
 5
1 5
2 3
2 4
1 2
 8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
 7
5 6
5 7
5 1
7 4
6 3
3 2
 3
1 3
3 2
 2
1 2
 5
5 4
4 3
3 1
5 2
 6
1 6
3 1
6 4
5 3
2 5
 11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
 11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
 12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5

-1
 9
 1
 1
 3
 3
 -1
 -1
 1
 1
 1
 5
 1
 5
 -1

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define bitcount __builtin_popcount
#define pw(x) (1LL<<(x))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define endl '\n'
#define next ____next
#define prev ____prev
#define hash ____hash
#define left ____left
#define to ____to
#define y1 ____y1
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << endl;})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<endl;})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<endl;})
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3fll;
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE {cout << -1 << endl; exit(0);}
//------------------------------------------------------------------------------------------------------

const int N = 2e5 + 10;
VI a[N];
int deg[N], n, path[N];
bool change = false;
bool gone[N];
int cent = -1;
int sz[N];
int tot = 0;

void dfs_cent(int u, int pre) {
    sz[u] = 1;
    bool ok = true;
    for(auto v : a[u]) {
        if(v == pre) continue;
        if(gone[v]) continue;
        dfs_cent(v, u);
        sz[u] += sz[v];
        if(sz[v] > (double)tot/2) ok = false;
    }
    if(sz[u] < (double)tot/2) ok = false;
    if(ok) cent = u;
}

void dfs_pre(int u, int pre) {
    set<int> S;
    int validcnt = 0;
    int only_child = -1;
    for(auto v : a[u]) {
        if(v == pre) continue;
        if(gone[v]) continue;
        dfs_pre(v, u);
        if(path[v] != -1) {
            if(S.count(path[v])) {
                gone[v] = true;
                change = true;
                deg[u]--;
            }
            else S.insert(path[v]);
        }
        if(!gone[v]) {
            validcnt++;
            if(path[v] != -1) only_child = v;
        }
    }
    if(validcnt == 0) {
        path[u] = 0;
    } else if (validcnt == 1 and only_child != -1) {
        path[u] = 1 + path[only_child];
    }
}

int dfs_cnt(int u, int pre) {
    int ret = 1;
    for(auto v : a[u]) {
        if(v == pre) continue;
        if(gone[v]) continue;
        ret += dfs_cnt(v, u);
    }
    return ret;
}

int main() {
    cin >> n;
    REP(i, n-1) {
        int u, v;
        cin >> u >> v;
        a[--u].eb(--v);
        a[v].eb(u);
        deg[u]++;
        deg[v]++;
    }

    while(1) {
        change = false;
        REP(i, n) if(!gone[i]) { tot = dfs_cnt(i, -1); break; }
        REP(i, n) if(!gone[i]) {
            memset(sz, 0, sizeof sz);
            dfs_cent(i, -1);
            break;
        }
        memset(path, -1, sizeof path);
        dfs_pre(cent, -1);
        if(!change) break;
    }

    REP(i, n) if(!gone[i] and deg[i] >= 3) DIE;

    REP(i, n) if(!gone[i]) { tot = dfs_cnt(i, -1); break; }

    cout << tot-1 << endl;






























    return 0;
}
