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

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {

        new Main().solve();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.0000000001;

    PrintWriter out;

    int n;
    int m;

    ArrayList<Integer>[] g;

    void solve() throws IOException {

        Reader in;
        BufferedReader br;

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }

        int n = in.nextInt();
        g = new ArrayList[n];
        cnt = n;

        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
            c[i] = new TreeSet<>();
        }

        for (int i = 0; i < n-1; i++) {
            int x = in.nextInt()-1;
            int y = in.nextInt()-1;
            g[x].add(y);
            g[y].add(x);
            degs[x]++;
            degs[y]++;
        }

        dfs1(0, -1);
        dfs2(0, -1);

        if (ok) {

            if (cnt%2 == 0)
                out.println(cnt-1);
            else
                out.println(1);
        }
        else
            out.println(-1);

        out.flush();
        out.close();
    }

    TreeSet<Integer>[] c = new TreeSet[200000];
    int[] degs = new int[2000000];
    boolean[] used = new boolean[2000000];
    int cnt = 0;
    boolean ok = true;

    void dfs1(int v, int p) {

        for (int u : g[v]) {

            if (u == p)
                continue;

            dfs1(u, v);
            if (degs[u] <= 1 && c[u].size() <= 1) {

                int sz = 1;
                if (c[u].size() != 0) {
                    sz = c[u].first()+1;
                }

                if (c[v].contains(sz)) {
                    cnt -= sz;
                }
                else
                    c[v].add(sz);

                degs[v]--;
                used[u] = true;
            }
        }
    }

    void dfs2(int v, int p) {

        if (p != -1) {
            if (degs[p] <= 1 && c[p].size() <= 1) {
                int sz = 1;
                if (c[p].size() != 0)
                    sz = c[p].first()+1;
                if (c[v].contains(sz))
                    cnt -= sz;
                c[v].add(sz);
                degs[v]--;
            }
        }

//        System.err.println(v);
//        System.err.println(degs[v]);
//        System.err.println(c[v]);

        if (c[v].size() > 2 || degs[v] > 1) {
            ok = false;
            return;
        }

        if (degs[v] == 1 && c[v].size() == 2) {
            ok = false;
            return;
        }

        for (int u : g[v]) {

            if (u != p && !used[u]) {
                dfs2(u, v);
                if (degs[u] > 0 || c[u].size() > 2) {
                    ok = false;
                    return;
                }
                degs[v]--;
            }
        }

    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;


        Pair(int a, int b) {

            this.a = a;
            this.b = b;

        }

        public int compareTo(Pair p) {
            if (a > p.a) return 1;
            if (a < p.a) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}