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>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vvvpii = vector<vvpii>;
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& P) {
  is >> P.first;
  is >> P.second;
  return is;
}
template <class T>
T read() {
  T t;
  cin >> t;
  return t;
}
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  return o << '(' << p.first << ", " << p.second << ')';
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& t) {
  o << "{";
  for (int i = int(0); i < int(((int)(t).size())); ++i) o << t[i] << ",";
  o << "}" << endl;
  return o;
}
vs s_p_l_i_t(const string& s, char c) {
  vs v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void e_r_r(vs::iterator it) { cerr << endl; }
template <class T, class... Args>
void e_r_r(vs::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  e_r_r(++it, args...);
}
ll solve() {
  int n = read<int>();
  vvi E(n);
  for (int i = int(0); i < int(n - 1); ++i) {
    int u = read<int>() - 1;
    int v = read<int>() - 1;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vi par(n);
  vector<map<int, int>> info(n);
  auto pinfo = [&]() {
    for (int i = int(0); i < int(n); ++i) {
      cout << i << ": ";
      for (auto&& lc : info[i]) {
        cout << lc << ", ";
      }
      cout << endl;
    }
  };
  int root = 0;
  function<void(int, int)> dfs1 = [&](int cur, int pre) {
    par[cur] = pre;
    if (((int)(E[cur]).size()) == 1) {
      info[cur][0] = 1;
    }
    for (auto&& nex : E[cur]) {
      if (nex != pre) {
        dfs1(nex, cur);
        for (auto&& lc : info[nex]) {
          info[cur][lc.first + 1] += lc.second;
        }
      }
    }
  };
  dfs1(root, -1);
  {
    function<void(int, int)> dfs = [&](int cur, int pre) {
      if (pre != -1) {
        for (auto it = info[pre].rbegin(); it != info[pre].rend(); it++) {
          int len = it->first;
          int cnt = it->second;
          if (cnt == 0) continue;
          int clen1 = 0;
          if (info[cur].count(len - 1)) clen1 = info[cur][len - 1];
          if (cnt - clen1 == 0) continue;
          info[cur][len + 1] += cnt - clen1;
        }
      }
      for (auto&& nex : E[cur]) {
        if (nex != pre) {
          dfs(nex, cur);
        }
      }
    };
    dfs(root, -1);
  }
  for (int i = int(0); i < int(n); ++i) {
    if (((int)(info[i]).size()) <= 2) {
      for (int j = int(0); j < int(n); ++j) info[j].clear();
      dfs1(i, -1);
      for (int j = int(0); j < int(n); ++j)
        if (j != i) {
          if (j != i && ((int)(info[j]).size()) >= 2) return -1;
        }
      int ans = 0;
      for (auto&& lc : info[i]) {
        ans += lc.first;
      }
      return ans;
    }
  }
  return -1;
}
void Main() { cout << solve() << endl; }
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Main();
  return 0;
}
