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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ArrayList;

public class Main{
  public static class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;
    
    public InputReader (InputStream stream){
      reader = new BufferedReader(new InputStreamReader(stream));
    }
    
    public String next(){
      while(tokenizer == null || !tokenizer.hasMoreTokens()){
        try{
          String line = reader.readLine();
          if(line == null){
            return "0";
          }
          tokenizer = new StringTokenizer(line);
        } catch(IOException ioe){
          throw new RuntimeException(ioe);
        }
      }
      return tokenizer.nextToken();
    }
    
    public int nextInt(){
      return Integer.parseInt(next());
    }
    
    public double nextDouble(){
      return Double.parseDouble(next());
    }
    
    public Long nextLong(){
      return Long.parseLong(next());
    }
    
    public BigInteger nextBigInteger(){
      return new BigInteger(next());
    }
    
    public String nextLine(){
      String line = "";
      try{
        while(line.equals("")){
          line = reader.readLine();
        }
      } catch(IOException ioe){
        throw new RuntimeException(ioe);
      }
      return line;
    }
  }
  
  public static int reduce(int n){
    return 1;
  } 
  
  
  public static class CenterFinder{
    boolean[] visited;
    int[] onPath;
    int n;
    ArrayList<ArrayList<Integer> > tree;
    public CenterFinder(int n , ArrayList<ArrayList<Integer> > tree){
      this.tree = tree;
      this.visited = new boolean[n+1];
      this.onPath = new int[n+1];
      this.n = n;
    }
    public int getCenter(){
      int one = bfs(1);
      int other = bfs(one);
      dist(one, other, 1);
      int max = 0;
      for(int i=1;i<=n;++i){
        max = Math.max(max, onPath[i]);
      }
      int centDepth = (max+1)/2;
      for(int i=1;i<=n;++i){
        if(onPath[i] == centDepth){
          return i;
        }
      }
      return -1;
    }
    
    public int bfs(int v){
      int last = 0;
      LinkedList<Integer> q = new LinkedList<Integer>();
      q.add(v);
      visited[v] = true;
      while(q.size()>0){
        int node = last = q.poll();
        visited[node] = true;
        for(int ne : tree.get(node)){
          if(!visited[ne]){
            q.add(ne);
          }
        }
      }
      for(int i=0;i<n;++i){
        visited[i+1] = false;
      }
      return last;
    }
    
    public boolean dist(int v, int u, int depth){
      if(u == v){
        onPath[v] = depth;
        return true;
      }
      visited[v] = true;
      for(int ne : tree.get(v)){
        if(!visited[ne]){
          if(dist(ne,u,depth+1)){
            onPath[v] = depth;
            return true;
          }
        }
      }
      return false;
    }
  }
  
  public static int count(int v, boolean[] visited, ArrayList<ArrayList<Integer> > tree){
    int len = 0;
    visited[v] = true;
    for(int ne : tree.get(v)){
      if(!visited[ne]){
        int rec = count(ne, visited, tree);
        if(rec == -1 || (len > 0 && len != rec)){
          return -1;
        }
        if(len == 0){
          len = rec;
        }
      }
    }
    return len+1;
  }
  
  public static int solve(ArrayList<ArrayList<Integer> > tree, int[] degs, int n){
    if(n <= 2){
      return n-1;
    }
//     System.out.println(tree);
    CenterFinder finder = new CenterFinder(n,tree);
    int cent = finder.getCenter();
//     System.out.println(cent);
    boolean[] visited = new boolean[n+1];
    
    visited[cent] = true;
    int one = 0;
    int other = 0;
    for(int ne : tree.get(cent)){
      int depth  = count(ne, visited, tree);
      if(depth == -1){
        return -1;
      }
      if(one == 0){
        one = depth;
        continue;
      }
      if(depth != one && other == 0){
        other = depth;
        continue;
      }
      if(depth != one && depth != other){
        return -1;
      }
    }
    int k = one + other + 1;
    while((k&1) > 0 && k >1){
      k = k/2+1;
    }
    return k-1;
    
  }
  
  public static void main(String[] args){
    InputReader reader = new InputReader(System.in);
    PrintWriter pw = new PrintWriter(System.out);
    int n = reader.nextInt();
    ArrayList<ArrayList<Integer> > tree = new ArrayList<ArrayList<Integer> > (n+1);
    for(int i=0;i<=n;++i){
      tree.add(new ArrayList<Integer>());
    }
    int[] deg = new int[n+1];
    for(int i=0;i<n;++i){
      int a = reader.nextInt();
      int b = reader.nextInt();
      tree.get(a).add(b);
      tree.get(b).add(a);
      deg[a]++;
      deg[b]++;
    }
    
    pw.printf("%d\n", solve(tree, deg, n));
    pw.flush();
    pw.close();
    
  }
}