#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll_t=long long;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> V(n);
    for (int i = 1; i < n; i++)
        cin >> V[i].first >> V[i].second;

    if (n%2 != 0)
    {
        cout << -1 << endl;
        return 0;
    }

    int R(0);
    int max_c(1);
    map<int, int> CU;
    map<int, int> VC;
    for (int i = 1; i < n; i++)
    {
        auto c1 = VC.find(V[i].first);
        auto c2 = VC.find(V[i].second);
        if (c1 == VC.end() && c2 == VC.end())
        {
            VC[V[i].first] = max_c;
            VC[V[i].second] = max_c;
            CU[max_c] += 2;
            max_c++;
        }
        else if (c1 != VC.end() && c2 == VC.end())
        {
            CU[c1->second]++;
            VC[V[i].second] = c1->second;
        }
        else if (c1 == VC.end() && c2 != VC.end())
        {
            CU[c2->second]++;
            VC[V[i].first] = c2->second;
        }
        else
        {
            //cout << "aa " << c1->second << ' ' <<  c2->second << endl;
            if (c1->second == c2->second)
            {
                R++;
            }
            else
            {
                CU[c1->second] += CU[c2->second];
                CU[c2->second] = -1;
                for (auto& vc : VC)
                    if (vc.second == c2->second)
                        vc.second = c1->second;
                /*cout << "bb " << CU[c1->second] << ' ' <<  CU[c2->second] << endl;
                cout << "cc " << CU[c1->second] << ' ' <<  CU[c2->second] << endl;*/
            }
        }
    }

    for (const auto& cu : CU)
    {
        //cout << cu.first << ' ' << cu.second << endl;
        if (cu.second == -1)
            continue;
        if (cu.second%2 != 0)
        {
            cout << -1 << endl;
            return 0;
        }

        R += (cu.second - 1) - (cu.second / 2);
    }

    cout << R << endl;

    return 0;
}


#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using ll = long long;

void dfs(int p, int v, const multimap<int, int>& Adj, vector<int>& S)
{
    S[v] = 1;
    auto iter = Adj.lower_bound(v);
    auto end = Adj.upper_bound(v);
    while (iter != end)
    {
        if (p != iter->second)
        {
            dfs(v, iter->second, Adj, S);
            S[v] += S[iter->second];
        }
        ++iter;
    }
}

int main()
{
    int n;
    cin >> n;
    multimap<int, int> Adj;
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        Adj.insert(make_pair(u, v));
        Adj.insert(make_pair(v, u));
    }
    vector<int> S(n+1);
    dfs(0, 1, Adj, S);
    int Ans = -1;
    for (int i = 1; i <= n; i++)
        Ans += (S[i]%2 == 0 ? 1 : 0);
    cout << Ans << '\n';
    return 0;
}


#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using ll = long long;

void dfs(int p, int v, const multimap<int, int>& Adj, vector<int>& S)
{
    S[v] = 1;
    auto iter = Adj.lower_bound(v);
    auto end = Adj.upper_bound(v);
    while (iter != end)
    {
        if (p != iter->second)
        {
            dfs(v, iter->second, Adj, S);
            S[v] += S[iter->second];
        }
        ++iter;
    }
}

int main()
{
    int n;
    cin >> n;
    multimap<int, int> Adj;
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        Adj.insert(make_pair(u, v));
        Adj.insert(make_pair(v, u));
    }
    if (n%2 != 0)
    {
        cout << -1 << '\n';
        return 0;
    }
    vector<int> S(n+1);
    dfs(0, 1, Adj, S);
    int Ans = -1;
    for (int i = 1; i <= n; i++)
        Ans += (S[i]%2 == 0 ? 1 : 0);
    cout << Ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 1;
set<int> arr[maxN + 1];
int nodeSize[maxN + 1];

void dfs(int cur, int par)
{
    //cout << cur << "\n";
    auto it = arr[cur].begin();
    while (it != arr[cur].end())
    {
        if (*it == par)
        {
            it++;
            continue;
        }
        else
        {
            dfs(*it, cur);
            nodeSize[cur] += nodeSize[*it];
            it++;
        }
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        arr[a].insert(b);
        arr[b].insert(a);
    }
    if (n & 1)
    {
        cout << "-1";
        return 0;
    }
    fill(nodeSize, nodeSize + maxN, 1);
    dfs(1, -1);
    //cout << "----\n";
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        //cout << nodeSize[i] << "\n";
        if (!(nodeSize[i] & 1))
        {
            ans++;
        }
    }
    cout << ans - 1;
    /*queue<int> q;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i].size() == 1)
        {
            q.push(i);
        }
    }
    if (n % 2 == 1)
    {
        cout << "-1\n";
        return 0;
    }
    bool visited[n + 1];
    fill(visited, visited + n + 1, false);
    while (!q.empty())
    {
        int a;
        a = q.front(); //get edge
        //cout << a << "\n";
        q.pop();*/
    /*if (arr[a].size() == 0)
        {
            if (n % 2 == 0)
            {
                cout << "0\n";
            }
            else
                cout << "-1\n";
            return 0;
        }*/
    /*
        auto it = arr[a].begin();
        int other = *it; //get its edge vertex
        visited[a] = true;
        visited[other] = true;
        it = arr[other].begin();
        while (it != arr[other].end()) //iterate through all the edges of other
        {
            int element = *it; //get the element it borders
            if (element == a)
            {
                it++;
                continue;
            }
            //cout << element << "\n";
            auto remove = arr[element].find(other); //remove the element other from border vertex
            arr[element].erase(remove);
            ans++;
            if (arr[element].size() == 1)
            {
                q.push(element);
            }*/
    /*else if (arr[element].size() == 0)
            {
                if (n % 2 == 0)
                {
                    cout << "0\n";
                }
                else
                    cout << "-1\n";
                return 0;
            }*/
    //cout << "ok\n";
    //it++;
    //cout << "ok\n";
    //}
    //}
    /*for (int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            cout << "-1\n";
            return 0;
        }
    }*/
    //cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    set<int> arr[n + 1];
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        arr[a].insert(b);
        arr[b].insert(a);
    }
    queue<int> q;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i].size() == 1)
        {
            q.push(i);
        }
    }
    bool visited[n + 1];
    fill(visited, visited + n + 1, false);
    while (!q.empty())
    {
        int a;
        a = q.front(); //get edge
        //cout << a << "\n";
        q.pop();
        if (arr[a].size() == 0)
        {
            if (n % 2 == 0)
            {
                cout << "0\n";
            }
            else
                cout << "-1\n";
            return 0;
        }
        auto it = arr[a].begin();
        int other = *it; //get its edge vertex
        visited[a] = true;
        visited[other] = true;
        it = arr[other].begin();
        while (it != arr[other].end()) //iterate through all the edges of other
        {
            int element = *it; //get the element it borders
            if (element == a)
            {
                it++;
                continue;
            }
            //cout << element << "\n";
            auto remove = arr[element].find(other); //remove the element other from border vertex
            arr[element].erase(remove);
            ans++;
            if (arr[element].size() == 1)
            {
                q.push(element);
            }
            else if (arr[element].size() == 0)
            {
                if (n % 2 == 0)
                {
                    cout << "0\n";
                }
                else
                    cout << "-1\n";
                return 0;
            }
            //cout << "ok\n";
            it++;
            //cout << "ok\n";
        }
    }
    if (n == 1)
    {
        cout << "-1\n";
        return 0;
    }
    /*for (int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            cout << "-1\n";
            return 0;
        }
    }*/
    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    set<int> arr[n + 1];
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        arr[a].insert(b);
        arr[b].insert(a);
    }
    queue<int> q;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i].size() == 1)
        {
            q.push(i);
        }
    }
    bool visited[n + 1];
    fill(visited, visited + n + 1, false);
    while (!q.empty())
    {
        int a;
        a = q.front(); //get edge
        //cout << a << "\n";
        q.pop();
        if (arr[a].size() == 0)
        {
            cout << "-1\n";
            return 0;
        }
        auto it = arr[a].begin();
        int other = *it; //get its edge vertex
        visited[a] = true;
        visited[other] = true;
        it = arr[other].begin();
        while (it != arr[other].end()) //iterate through all the edges of other
        {
            int element = *it; //get the element it borders
            if (element == a)
            {
                it++;
                continue;
            }
            //cout << element << "\n";
            auto remove = arr[element].find(other); //remove the element other from border vertex
            arr[element].erase(remove);
            ans++;
            if (arr[element].size() == 1)
            {
                q.push(element);
            }
            else if (arr[element].size() == 0)
            {
                cout << "-1\n";
                return 0;
            }
            //cout << "ok\n";
            it++;
            //cout << "ok\n";
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            cout << "-1\n";
            return 0;
        }
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    set<int> arr[n + 1];
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        arr[a].insert(b);
        arr[b].insert(a);
    }
    queue<int> q;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i].size() == 1)
        {
            q.push(i);
        }
    }
    while (!q.empty())
    {
        int a;
        a = q.front(); //get edge
        //cout << a << "\n";
        q.pop();
        if (arr[a].size() == 0)
        {
            cout << "-1\n";
            return 0;
        }
        auto it = arr[a].begin();
        int other = *it; //get its edge vertex
        it = arr[other].begin();
        while (it != arr[other].end()) //iterate through all the edges of other
        {
            int element = *it; //get the element it borders
            if (element == a)
            {
                it++;
                continue;
            }
            //cout << element << "\n";
            auto remove = arr[element].find(other); //remove the element other from border vertex
            arr[element].erase(remove);
            ans++;
            if (arr[element].size() == 1)
            {
                q.push(element);
            }
            else if (arr[element].size() == 0)
            {
                cout << "-1\n";
                return 0;
            }
            //cout << "ok\n";
            it++;
            //cout << "ok\n";
        }
    }
    cout << ans << "\n";
}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
vector<int> ss;
int f;
void dfs(int n)
{
	int ans=0;
	v[n]=1;
	ss[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			dfs(al[n][i]);
			ss[n]+=ss[al[n][i]]

		}
	}

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	if(n%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	ss.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	dfs(1);
	f=0;
	for(i=1;i<n+1;i++)
	{
		if(ss[i]%2==0)
			f++;
	}

	cout<<f<<endl;
}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
vector<int> ss;
int f;
void dfs(int n)
{
	int ans=0;
	v[n]=1;
	ss[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			dfs(al[n][i]);
			ss[n]+=ss[al[n][i]];

		}
	}

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	if(n%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	ss.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	dfs(1);
	f=0;
	for(i=1;i<n+1;i++)
	{
		if(ss[i]%2==0)
			f++;
	}

	cout<<f<<endl;
}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
int f;
int dfs(int n)
{
	int ans=0;
	v[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			// ans++;
			int temp = dfs(al[n][i]);
			if(temp%2==0)
			{
				ans=ans+temp+1;
			}
			else
			{
				f++;
			}
		}
	}
	return ans;

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	if(n%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	f=0;
	int x = dfs(1);
	if(f)
		cout<<f<<endl;
	// else
	// {
	// 	if(n%2==0)
	// 		cout<<0<<endl;
	// 	else
	// 		cout<<-1<<endl;
	// }

}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
int f;
int dfs(int n)
{
    int ans=0;
    v[n]=1;
    int i;
    for(i=0;i<al[n].size();i++)
    {
        if(v[al[n][i]]==0)
        {
            // ans++;
            int temp = dfs(al[n][i]);
            if(temp%2==0)
            {
                ans=ans+temp+1;
            }
            else
            {
                f++;
            }
        }
    }
    return ans;

}

int main()
{
    int n,temp1,temp2;
    cin>>n;
    // vector<vector<int> >al;
    // if(n%2!=0)
    // {
    //     cout<<-1<<endl;
    //     return 0;
    // }
    al.assign(n+1,vector<int>());
    v.assign(n+1,0);
    int i;
    for(i=0;i<n-1;i++)
    {
        cin>>temp1>>temp2;
        al[temp1].push_back(temp2);
        al[temp2].push_back(temp1);
    }
    f=0;
    int x = dfs(1);
    if(x%2==0)
        cout<<-1<<endl;
    else
        cout<<f<<endl;
    // else
    // {
    //  if(n%2==0)
    //      cout<<0<<endl;
    //  else
    //      cout<<-1<<endl;
    // }

}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
int f;
int dfs(int n)
{
	int ans=0;
	v[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			// ans++;
			int temp = dfs(al[n][i]);
			if(temp%2==0)
			{
				ans=ans+temp+1;
			}
			else
			{
				f++;
			}
		}
	}
	return ans;

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	f=0;
	int x = dfs(1);
	if(f)
		cout<<f<<endl;
	else
	{
		if(n%2==0)
			cout<<0<<endl;
		else
			cout<<-1<<endl;
	}

}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
int f;
int dfs(int n)
{
	int ans=0;
	v[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			// ans++;
			int temp = dfs(al[n][i]);
			if(temp%2==0)
			{
				ans=ans+temp+1;
			}
			else
			{
				f++;
			}
		}
	}
	return ans;

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	if(n%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	f=0;
	int x = dfs(1);
		cout<<f<<endl;
	// else
	// {
	// 	if(n%2==0)
	// 		cout<<0<<endl;
	// 	else
	// 		cout<<-1<<endl;
	// }

}


// #include<cstdio>
// #include<cmath>
// // #include<cstdlib>
// // #include<cstring>
// #include<vector>
// // #include<string>
// // #include<iostream>
// // #include<stack>
// // #include<map>
// // #include<queue>
// #include <algorithm>
// #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
vector<vector<int> >al;
vector<int> v;
vector<int> ss;
int f;
void dfs(int n)
{
	int ans=0;
	v[n]=1;
	ss[n]=1;
	int i;
	for(i=0;i<al[n].size();i++)
	{
		if(v[al[n][i]]==0)
		{
			dfs(al[n][i]);
			ss[n]+=ss[al[n][i]];

		}
	}

}

int main()
{
	int n,temp1,temp2;
	cin>>n;
	// vector<vector<int> >al;
	if(n%2!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	al.assign(n+1,vector<int>());
	v.assign(n+1,0);
	ss.assign(n+1,0);
	int i;
	for(i=0;i<n-1;i++)
	{
		cin>>temp1>>temp2;
		al[temp1].push_back(temp2);
		al[temp2].push_back(temp1);
	}
	dfs(1);
	f=0;
	for(i=1;i<n+1;i++)
	{
		if(ss[i]%2==0)
			f++;
	}

	cout<<f-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int p[N],fa[N];
int ans=0;
vector<int> v[N];
vector<int> l;
void dfs(int s,int f)
{
	fa[s]=f;
	p[s]=1;
	int k,i,t;
	for(i=0;i<v[s].size();i++)
	{
		t=v[s][i];
		if(p[t]==1)
			continue;
		else
		{
			l.push_back(t);
			dfs(t,s);
		}
	}
	return;
}
int main()
{
	int i,a,b,n,s;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1)
		{
			s=i;
			break;
		}
	}
	l.push_back(s);
	dfs(s,-1);
	/*for(i=0;i<l.size();i++)
	{
		cout<<l[i]<<' ';
	}
	cout<<endl;*/
	if(n%2==1)
	{
		cout<<-1;
	}
	else
	{
		cout<<n/2-1;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
int hd[maxn],ne[maxn*2],to[maxn*2],num,n,siz[maxn],ans;
inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;}

void dfs(int x,int fa){
    siz[x]=1;
    for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa){
        dfs(to[i],x);
        siz[x]+=siz[to[i]];
    }

    if(!(siz[x]&1)) siz[x]=0,ans++;
}

int main(){
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++){
        scanf("%d%d",&uu,&vv);
        add(uu,vv),add(vv,uu);
    }

    if(n&1){ puts("-1"); return 0;}

    dfs(1,-1),ans--;

    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int p[N],fa[N];
int ans=0;
vector<int> v[N];
vector<int> l;
void dfs(int s,int f)
{
	fa[s]=f;
	p[s]=1;
	int k,i,t;
	for(i=0;i<v[s].size();i++)
	{
		t=v[s][i];
		if(p[t]==1)
			continue;
		else
		{
			l.push_back(t);
			dfs(t,s);
		}
	}
	return;
}
int main()
{
	ios::sync_with_stdio(false);
	int i,a,b,n,s;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1)
		{
			s=i;
			break;
		}
	}
	if(n%2==1)
	{
		cout<<-1;
		return 0;
	}
	l.push_back(s);
	dfs(s,-1);
	/*for(i=0;i<l.size();i++)
	{
		cout<<l[i]<<' ';
	}
	cout<<endl;*/
	cout<<n/2-1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int p[N],fa[N];
int ans=0;
vector<int> v[N];
vector<int> l;
void dfs(int s,int f)
{
	fa[s]=f;
	p[s]=1;
	int k,i,t;
	for(i=0;i<v[s].size();i++)
	{
		t=v[s][i];
		if(p[t]==1)
			continue;
		else
		{
			l.push_back(t);
			dfs(t,s);
		}
	}
	return;
}
int main()
{
	ios::sync_with_stdio(false);
	int i,a,b,n,s;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1)
		{
			s=i;
			break;
		}
	}
	if(n%2==1)
	{
		cout<<-1;
		return 0;
	}
	l.push_back(s);
	dfs(s,-1);
	/*for(i=0;i<l.size();i++)
	{
		cout<<l[i]<<' ';
	}
	cout<<endl;*/
	else
	{
		cout<<n/2-1;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> vect[100100];
int cnt[100100];
bool visited[100100];

int ans = 0;
int dfs(int i){
    if (visited[i])
        return 0;
    visited[i] = true;
    for (int ii = 0; ii < vect[i].size(); ++ii){

        cnt[i] = cnt[i] + dfs(vect[i][ii]);
    }

    //cout << "gia tri : " << cnt[i] << " " << i << endl;

    if (cnt[i] % 2 == 0 && i != 1)
        ans++;

    return cnt[i];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    memset(visited, false, sizeof(visited));

    cin >> n;
    for (int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;
        vect[u].push_back(v);
        vect[v].push_back(u);
        cnt[u] = 1;
        cnt[v] = 1;
    }

    if (n%2){
        cout << -1;
        return 0;
    }
    dfs(1);
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> vect[10010];
int cnt[10010];
bool visited[10010];

int ans = 0;
int dfs(int i){
    if (visited[i])
        return 0;
    visited[i] = true;
    for (int ii = 0; ii < vect[i].size(); ++ii){

        cnt[i] = cnt[i] + dfs(vect[i][ii]);
    }

    //cout << "gia tri : " << cnt[i] << " " << i << endl;

    if (cnt[i] % 2 == 0 && i != 1)
        ans++;
    return cnt[i];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    memset(visited, false, sizeof(visited));
    cin >> n;

    for (int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;
        vect[u].push_back(v);
        vect[v].push_back(u);
        cnt[u] = 1;
        cnt[v] = 1;
    }

    if (n%2){
        cout << -1;
        return 0;
    }
    dfs(1);
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> vect[10010];
int cnt[10010];
bool visited[10010];

int ans = 0;
int dfs(int i){
    if (visited[i])
        return 0;
    visited[i] = true;
    for (int ii = 0; ii < vect[i].size(); ++ii){

        cnt[i] = cnt[i] + dfs(vect[i][ii]);
    }

    //cout << "gia tri : " << cnt[i] << " " << i << endl;

    if (cnt[i] % 2 == 0 && i != 1)
        ans++;
    return cnt[i];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    memset(visited, false, sizeof(visited));
    scanf("%d", &n);
    if (n%2){
        cout << -1;
        return 0;
    }
    for (int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;
        vect[u].push_back(v);
        vect[v].push_back(u);
        cnt[u] = 1;
        cnt[v] = 1;
    }
    dfs(1);
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> vect[10010];
int cnt[10010];
bool visited[10010];

int ans = 0;
int dfs(int i){
    if (visited[i])
        return 0;
    visited[i] = true;
    for (int ii = 0; ii < vect[i].size(); ++ii){

        cnt[i] = cnt[i] + dfs(vect[i][ii]);
    }

    //cout << "gia tri : " << cnt[i] << " " << i << endl;

    if (cnt[i] % 2 == 0 && i != 1)
        ans++;
    return cnt[i];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    memset(visited, false, sizeof(visited));
    scanf("%d", &n);

    for (int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;
        vect[u].push_back(v);
        vect[v].push_back(u);
        cnt[u] = 1;
        cnt[v] = 1;
    }

    if (n%2){
        cout << -1;
        return 0;
    }
    dfs(1);
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mk make_pair
vector<int> v[50011];
bool vis[500111];
int c=1;
void dfs(int node)
{
    vis[node]=c;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])dfs(Node);
    }
}
////
int cnt=0;

int Dfs(int node,int C)
{
    ///cout<<node<<" "<<C<<endl;
    vis[node]=1;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])Dfs(Node,C+1);
    }
    if(C>0 && C%2==0)cnt++;
    return cnt;
}
////
vector<int> cmp[500111];
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(!vis[i])
        {
            dfs(i);
            c++;
        }
    }
    for(int i=1; i<=n; i++)
    {
        cmp[vis[i]].pb(i);
    }
    int ans=(int)1e9;
    memset(vis,0,sizeof vis);
    for(int i=1; i<=c; i++)
    {
        if(cmp[i].size()%2)return cout<<-1,0;
        else
        {
            int a=0,id;
            for(int j=0; j<cmp[i].size(); j++)
            {
//                if(v[cmp[i][j]].size()>a)
//                {
                memset(vis,0,sizeof vis);
                ans=min(Dfs(cmp[i][j],0),ans);
//                    a=v[cmp[i][j]].size();
//                    id=cmp[i][j];
//                }
            }

        }
    }
    cout<<endl;
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mk make_pair
vector<int> v[50011];
bool vis[500111];
int c=1;
void dfs(int node)
{
    vis[node]=c;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])dfs(Node);
    }
}
////
int cnt=0;

int Dfs(int node,int C)
{
    ///cout<<node<<" "<<C<<endl;
    vis[node]=1;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])Dfs(Node,C+1);
    }
    if(C>0 && C%2==0)cnt++;
    return cnt;
}
////
vector<int> cmp[500111];
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(!vis[i])
        {
            dfs(i);
            c++;
        }
    }
    for(int i=1; i<=n; i++)
    {
        cmp[vis[i]].pb(i);
    }
    int ans=(int)1e9;
    memset(vis,0,sizeof vis);
    for(int i=1; i<=c; i++)
    {
        if(cmp[i].size()%2)return cout<<-1,0;
        else
        {
            int a=0,id;
            for(int j=0; j<cmp[i].size(); j++)
            {
                if(v[cmp[i][j]].size()>a)
                {
                    a=v[cmp[i][j]].size();
                    id=cmp[i][j];
                }
            }
            memset(vis,0,sizeof vis);
            ans=min(Dfs(id,0),ans);
        }
    }
    cout<<endl;
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mk make_pair
vector<int> v[50011];
bool vis[500111];
int c=1;
void dfs(int node)
{
    vis[node]=c;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])dfs(Node);
    }
}
////
int cnt=0;

int Dfs(int node,int C)
{
    vis[node]=1;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])Dfs(Node,++C);
    }
    if(C>0 && C%2==0)cnt++;
    return cnt;
}
////
vector<int> cmp[500111];
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(!vis[i])
        {
            dfs(i);
            c++;
        }
    }
    for(int i=1; i<=n; i++)
    {
        cmp[vis[i]].pb(i);
    }
    int ans=(int)1e9;
    memset(vis,0,sizeof vis);
    for(int i=1; i<=c; i++)
    {
        if(cmp[i].size()%2)return cout<<-1,0;
        else
        {
            for(int j=0; j<cmp[i].size(); j++)
            {
                if(v[cmp[i][j]].size()==1)
                {
                memset(vis,0,sizeof vis);
                //cout<<Dfs(2,0);
                ans=min(Dfs(cmp[i][j],0),ans);
                break;
                }
            }
        }
    }
    cout<<endl;
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mk make_pair
vector<int> v[500111];
int cnt[500111];
bool vis[500111];
int dfs(int node)
{
    int ret=1;
    vis[node]=1;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])ret+=dfs(Node);
    }
    return cnt[node]=ret;
}
int ans;
int Dfs(int node)
{
    vis[node]=1;
    for(int i=0; i<v[node].size(); i++)
    {
        int Node=v[node][i];
        if(!vis[Node])Dfs(Node);
    }
    if(cnt[node]%2==0 && node!=1)ans++;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    if(n%2)return cout<<-1,0;
    dfs(1);
    memset(vis,0,sizeof vis);
    Dfs(1);
    cout<<ans;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> subtree_size(MAX_N, 0);

int dfs(int v, int parent)
{
    subtree_size[v] = 1;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        dfs(child, v);

        subtree_size[v] += subtree_size[child];
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);

    if(no_of_vertices%2 == 1)
    {
        printf("-1\n");
        return 0;
    }

    int answer = 0;

    for(int i = 2; i <= no_of_vertices; i++)
        answer += (subtree_size[i]%2 == 0);

    printf("%d\n", answer);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> subtree_size(MAX_N, 0);

int dfs(int v, int parent)
{
    subtree_size[v] = 1;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        dfs(child, v);

        subtree_size[v] += subtree_size[child];
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);

    if(no_of_vertices&1)
    {
        printf("-1\n");
        return 0;
    }

    int answer = 0;

    for(int i = 2; i <= no_of_vertices; i++)
        answer += (subtree_size[i]%2 == 0);

    printf("%d\n", answer);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> no_of_children(MAX_N, 0);

int dfs(int v, int parent)
{
    no_of_children[v] = 1;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        dfs(child, v);

        no_of_children[v] += no_of_children[child];
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);

    if(no_of_vertices%2 == 1)
    {
        printf("-1\n");
        return 0;
    }

    int answer = 0;

    for(int i = 2; i <= no_of_vertices; i++)
        answer += (no_of_children[i]%2 == 0);

    printf("%d\n", answer);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> no_of_children(MAX_N, 0);

int dfs(int v, int parent)
{
    no_of_children[v] = 1;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        dfs(child, v);

        no_of_children[v] += no_of_children[child];
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);

    if(no_of_vertices%2 == 1)
    {
        printf("-1\n");
        return 0;
    }

    int answer = 0;

    for(int i = 2; i < no_of_vertices; i++)
        answer += (no_of_children[i]%2 == 0);

    printf("%d\n", answer);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> subtree_size(MAX_N, 0);

void dfs(int v, int parent)
{
    subtree_size[v] = 1;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        dfs(child, v);

        subtree_size[v] += subtree_size[child];
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);

    if(no_of_vertices%2 == 1)
    {
        printf("-1\n");
        return 0;
    }

    int even_components = 0;

    for(int i = 2; i <= no_of_vertices; i++)
        even_components += (subtree_size[i]%2 == 0);

    printf("%d\n", even_components);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 1e5 + 15;
vector <int> graph[MAX_N];
vector <int> no_of_children(MAX_N, 0);

int dfs(int v, int parent)
{
    for(int i = 0; i < graph[v].size(); i++)
    {
        int child = graph[v][i];

        if(child == parent) continue;

        no_of_children[v]++;

        dfs(child, v);
    }
}

int main()
{
    int no_of_vertices;
    scanf("%d", &no_of_vertices);

    for(int i = 1; i < no_of_vertices; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1, 0);
    int answer = (no_of_vertices == 1 ? -1 : 0);

    for(int i = 2; i < no_of_vertices; i++)
        answer += (no_of_children[i]%2 == 0);

    printf("%d\n", answer);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
int main()
{
    //ifstream cin (duom);
    int n,x;
    cin >> n;
    for (int i=0;i<n*2;i++){cin >>x;}
    if (n%2==1){cout <<-1;}else{cout<<n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    if (n%2==1){cout <<-1;}else{cout<<n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100000);
int dp [100000];
int cuts=0;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;return 0;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    dp[1]=n-1;
    for (int i=1;i<=n;i++)if(dp[i]%2==0){cuts++;}
    cout <<cuts;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1)
    {
        dp[node]=1;
        return 1+1;
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    return dp[node]+1;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100001);
int dp [100001];
int cuts=0;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;return 0;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    for (int i=1;i<=n;i++)
    {
        if(dp[i]%2==0)
        {
            cuts++;
        }
    }
    cout <<cuts-1;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1&&node!=1)
    {
        dp[node]=1;
        return dp[node];
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    dp[node]+=1;
    return dp[node];
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100000);
int dp [100000];
int cuts=1;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    dp[1]=n-1;
    for (int i=1;i<=n;i++)if(dp[i]%2==0){cuts++;}
    cout <<cuts;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1)
    {
        dp[node]=1;
        return 1+1;
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    return dp[node]+1;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
int main()
{
    //ifstream cin (duom);
    int n,x;
    cin >> n;
    for (int i=0;i<(n-1)*2;i++){cin >>x;}
    if (n%2==1){cout <<-1;}else{cout<<n/2-1;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100000);
int dp [100000];
int cuts=0;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;return 0;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    for (int i=1;i<=n;i++)
    {
        if(dp[i]%2==0)
        {
            cuts++;
        }
    }
    cout <<cuts-1;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1&&node!=1)
    {
        dp[node]=1;
        return dp[node];
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    dp[node]+=1;
    return dp[node];
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100000);
int dp [100000];
int cuts=0;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    dp[1]=n-1;
    for (int i=1;i<=n;i++)if(dp[i]%2==0){cuts++;}
    cout <<cuts;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1)
    {
        dp[node]=1;
        return 1+1;
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    return dp[node]+1;
}


#include <bits/stdc++.h>

using namespace std;
const char duom [] ="i.txt";
vector <vector <int>> kaimynai(100000);
int dp [100000];
int cuts=0;
int dfs (int node,int prev);
int main()
{
    //ifstream cin (duom);
    int n;
    cin >> n;
    int x,y;
    if(n%2==1){cout <<-1;return 0;}
    for(int i=0;i<n-1;i++)
    {
        cin >> x >> y;
        kaimynai[x].push_back(y);
        kaimynai[y].push_back(x);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++){cout <<dp[i]<<endl;}
    for (int i=1;i<=n;i++)
    {
        if(dp[i]%2==0)
        {
            cuts++;
        }
    }
    cout <<cuts-1;
    return 0;
}
int dfs (int node,int prev)
{
    if(kaimynai[node].size()==1&&node!=1)
    {
        dp[node]=1;
        return dp[node];
    }
    for(int i=0;i<kaimynai[node].size();i++)
    {
        if (kaimynai[node][i]==prev){continue;}
        dp[node]+=dfs(kaimynai[node][i],node);
    }
    dp[node]+=1;
    return dp[node];
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef map<pi,int> mpi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
int res;
int dfs(int x,vi v[],int p)
{
    int sum=0;
    fri(v[x].size()){
        if(v[x][i]!=p)
            sum+=dfs(v[x][i],v,x);
    }
    if(sum%2)res++;
    return sum+1;
}
void solve()
{
    int n;cin>>n;
    vi v[n];
    vii vec(n-1);
    fri(n-1){
        int a,b;cin>>a>>b;a--;b--;
        vec[i]={a,b};
        v[b].pb(a);
        v[a].pb(b);
    }
    if(n%2)cout<<-1;
    else{
        res=0;
        dfs(0,v,0);
        cout<<res-1;
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //T(t)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
void dfs(int x,vi v[],vi &vis,int* len)
{
    vis[x]=1;
    *len+=1;
    fri(v[x].size())if(vis[v[x][i]]==0)dfs(v[x][i],v,vis,len);
}
void solve()
{
    int n;cin>>n;
    vi v[n];
    vii vec(n-1);
    fri(n-1){
        int a,b;cin>>a>>b;a--;b--;
        vec[i]={a,b};
        v[b].pb(a);
        v[a].pb(b);
    }
    if(n%2!=0)cout<<-1;
    else{
        vi vis(n);
        fri(n)
        {
            if(vis[i]==0){
                int len=0;
                dfs(i,v,vis,&len);
                if(len%2!=0){
                    cout<<-1;
                    return;}
            }
        }
        int res=0;
        fri(n-1){
            vi vis(n);
            vis[vec[i].S]=1;
            int len=0;
            dfs(vec[i].F,v,vis,&len);
            if(len%2==0)res++;
        }
        cout<<res;
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //T(t)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef map<pi,int> mpi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
int dfs(int x,vi v[],vi &vis)
{
    vis[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(vis[v[x][i]]==0){
            sum+=dfs(v[x][i],v,vis);
        }
    }
    return sum+1;
}
int go(int x,vi v[],vi &visi,mpi &m)
{
    visi[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(visi[v[x][i]]==0){
            if(m[{v[x][i],x}]!=0){
                sum+=m[{v[x][i],x}];
                //cout<<m[{v[x][i],x}];
            }
            else{
                m[{x,v[x][i]}]=m[{v[x][i],x}]=go(v[x][i],v,visi,m);
                sum+=m[{v[x][i],x}];
            }
        }
    }
    return sum+1;
}
void solve()
{
    int n;cin>>n;
    vi v[n];
    vii vec(n-1);
    fri(n-1){
        int a,b;cin>>a>>b;a--;b--;
        vec[i]={a,b};
        v[b].pb(a);
        v[a].pb(b);
    }
    if(n%2!=0)cout<<-1;
    else{
        vi vis(n);
        fri(n)
        {
            if(vis[i]==0){
                int len;
                len=dfs(i,v,vis);
                if(len%2!=0){
                    cout<<-1;
                    return;}
            }
        }
        int res=0;
        mpi m;
        vi visi(n);
        int len=0;
        fri(n-1){
            if(m[vec[i]]==0){
                if(visi[vec[i].F]==0&&visi[vec[i].S]==0){
                    visi[vec[i].S]=1;
                    m[{vec[i].S,vec[i].F}]=m[vec[i]]=go(vec[i].F,v,visi,m);
                }
                else if(visi[vec[i].F]==0){
                    m[{vec[i].S,vec[i].F}]=m[vec[i]]=go(vec[i].F,v,visi,m);
                }
                else{
                    m[{vec[i].S,vec[i].F}]=m[vec[i]]=go(vec[i].S,v,visi,m);
                }
                len=m[vec[i]];
            }
            else len=m[vec[i]];
            //cout<<len<<" ";
            if(len%2==0)res++;
        }
        cout<<res;
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //T(t)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef map<pi,int> mpi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
int dfs(int x,vi v[],vi &vis)
{
    vis[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(vis[v[x][i]]==0){
            sum+=dfs(v[x][i],v,vis);
        }
    }
    return sum+1;
}
int go(int x,vi v[],vi &visi,mpi &m)
{
    visi[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(visi[v[x][i]]==0){
            if(m[{v[x][i],x}]!=0){
                sum+=m[{v[x][i],x}];
                //cout<<m[{v[x][i],x}];
            }
            else{
                m[{x,v[x][i]}]=m[{v[x][i],x}]=go(v[x][i],v,visi,m);
                sum+=m[{v[x][i],x}];
            }
        }
    }
    return sum+1;
}
void solve()
{
    int n;cin>>n;
    vi v[n];
    vii vec(n-1);
    fri(n-1){
        int a,b;cin>>a>>b;a--;b--;
        vec[i]={a,b};
        v[b].pb(a);
        v[a].pb(b);
    }
    if(n%2!=0)cout<<-1;
    else{
        vi vis(n);
        fri(n)
        {
            if(vis[i]==0){
                int len;
                len=dfs(i,v,vis);
                if(len%2!=0){
                    cout<<-1;
                    return;}
            }
        }
        int res=0;
        mpi m;
        vi visi(n);
        int len=0;
        fri(n-1){
            if(m[vec[i]]==0){
                if(visi[vec[i].F]==0){
                    visi[vec[i].S]=1;
                    m[{vec[i].S,vec[i].F}]=m[vec[i]]=go(vec[i].F,v,visi,m);
                }
                else{
                    m[{vec[i].S,vec[i].F}]=m[vec[i]]=go(vec[i].S,v,visi,m);
                }
                len=m[vec[i]];
            }
            else len=m[vec[i]];
            if(len%2==0)res++;
        }
        cout<<res;
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //T(t)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef map<pi,int> mpi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
int dfs(int x,vi v[],vi &vis)
{
    vis[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(vis[v[x][i]]==0){
            sum+=dfs(v[x][i],v,vis);
        }
    }
    return sum+1;
}
int go(int x,vi v[],vi &visi,mpi &m)
{
    visi[x]=1;
    int sum=0;
    fri(v[x].size()){
        if(visi[v[x][i]]==0){
            if(m[{v[x][i],x}]!=0){
                sum+=m[{v[x][i],x}];
            }
            else{
                m[{x,v[x][i]}]=m[{v[x][i],x}]=go(v[x][i],v,visi,m);
                sum+=m[{v[x][i],x}];
            }
        }
    }
    return sum+1;
}
void solve()
{
    int n;cin>>n;
    vi v[n];
    vii vec(n-1);
    fri(n-1){
        int a,b;cin>>a>>b;a--;b--;
        vec[i]={a,b};
        v[b].pb(a);
        v[a].pb(b);
    }
    if(n%2!=0)cout<<-1;
    else{
        vi vis(n);
        fri(n)
        {
            if(vis[i]==0){
                int len;
                len=dfs(i,v,vis);
                if(len%2!=0){
                    cout<<-1;
                    return;}
            }
        }
        int res=0;
        mpi m;
        vi visi(n);
        int len=0;
        fri(n-1){
            if(m[vec[i]]==0){
                visi[vec[i].S]=1;
                m[vec[i]]=go(vec[i].F,v,visi,m);
                len=m[vec[i]];
            }
            else len=m[vec[i]];
            if(len%2==0)res++;
        }
        cout<<res;
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //T(t)
    {
        solve();
    }
}


/* Man's not hot! Man can never be hot! */
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
vector <int> adj[100005];
int vis[100005],child[100005];
int dfs(int x)
{
    vis[x]=1;
    int i;
    //cout<<x<<"\n";
    child[x]=1;
    FOR(i,0,adj[x].size())
    {
        int y=adj[x][i];
        if(vis[y])
            continue;
        dfs(y);
        child[x]+=child[y];
    }
}
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,x,y;
    cin>>n;

    FOR(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    if(n&1)
    {
        cout<<-1;
        return 0;
    }
    int rt;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
        {
            rt=i;
            break;
        }
    }
    //cout<<rt<<" ";
    dfs(rt);
    /*FOR(i,1,n+1)
    child[i]--;*/
    int ans=0;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
            continue;
        if((child[i]%2==0 && (n-child[i])%2==0) || ((child[i]-1)%2==0 && (n-child[i]+1)%2==0))
            ans++;
         /*   if(child[i]%2==0)
                ans++;*/
    }
    cout<<(ans+1)/2;
    return 0;
}


/* Man's not hot! Man can never be hot! */
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
vector <int> adj[100005];
int vis[100005],child[100005];
int dfs(int x)
{
    vis[x]=1;
    int i;
    child[x]=1;
    FOR(i,0,adj[x].size())
    {
        int y=adj[x][i];
        if(vis[y])
            continue;
        dfs(y);
        child[x]+=child[y];
    }
}
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,x,y;
    cin>>n;

    FOR(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    if(n&1)
    {
        cout<<-1;
        return 0;
    }
    int rt;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
        {
            rt=i;
            break;
        }
    }
    dfs(rt);
    int ans=0;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
            continue;
        if(child[i]%2==0)
                ans++;
    }
    cout<<ans;
    return 0;
}


/* Man's not hot! Man can never be hot! */
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
vector <int> adj[100005];
int vis[100005],child[100005];
int dfs(int x)
{
    vis[x]=1;
    int i;
    //cout<<x<<"\n";
    child[x]=1;
    FOR(i,0,adj[x].size())
    {
        int y=adj[x][i];
        if(vis[y])
            continue;
        dfs(y);
        child[x]+=child[y];
    }
}
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,x,y;
    cin>>n;

    FOR(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    if(n&1)
    {
        cout<<-1;
        return 0;
    }
    int rt;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
        {
            rt=i;
            break;
        }
    }
    //cout<<rt<<" ";
    dfs(rt);
    /*FOR(i,1,n+1)
    child[i]--;*/
    int ans=0;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
            continue;
       /* if((child[i]%2==0 && (n-child[i])%2==0) || ((child[i]+1)%2==0 && (n-child[i]-1)%2==0))
            ans++;*/
            if(child[i]%2==0)
                ans++;
    }
    if(ans==0)
        ans=-1;
    cout<<ans;
    return 0;
}


/* Man's not hot! Man can never be hot! */
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
vector <int> adj[100005];
int vis[100005],child[100005];
int dfs(int x)
{
    vis[x]=1;
    int i;
    //cout<<x<<"\n";
    child[x]=1;
    FOR(i,0,adj[x].size())
    {
        int y=adj[x][i];
        if(vis[y])
            continue;
        dfs(y);
        child[x]+=child[y];
    }
}
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,x,y;
    cin>>n;

    FOR(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    if(n&1)
    {
        cout<<-1;
        return 0;
    }
    int rt;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
        {
            rt=i;
            break;
        }
    }
    //cout<<rt<<" ";
    dfs(rt);
    /*FOR(i,1,n+1)
    child[i]--;*/
    int ans=0;
    FOR(i,1,n+1)
    {
        if(adj[i].size()==1)
            continue;
       /* if((child[i]%2==0 && (n-child[i])%2==0) || ((child[i]+1)%2==0 && (n-child[i]-1)%2==0))
            ans++;*/
            if(child[i]%2==0)
                ans++;
    }
    cout<<ans;
    return 0;
}


// http://codeforces.com/problemset/problem/982/C

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define eps 1e-10
#define fi first
#define se second
#define MOD1 1000000007LL
#define MOD 1000000009LL
#define p1 53
#define se second
#define inf 20000000000LL
#define pb push_back

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

ll modx(ll base, ll ex)
{
    ll ans = 1LL, val = base;
    while(ex > 0LL)
    {
        if(ex&1LL)
            ans = (ans*val)%MOD;
        val = (val*val)%MOD;
        ex = ex>>1LL;
    }
    return ans;
}

const int maxn = 1e5 + 5;
vector<int> adj[maxn], v[maxn];
bool visit[maxn];
int parent[maxn], level[maxn];
int cnt[maxn];
int n, m, x, y, maxx;

void dfs(int start, int depth, int par){

    visit[start] = true;
    level[start] = depth;
    parent[start] = par;
    cnt[start] = 1;
    maxx = max(maxx, depth);

    for(int i=0; i<adj[start].size(); i++){
        int pt = adj[start][i];

        if(!visit[pt]){
            dfs(pt, depth+1, start);
            cnt[start]+=cnt[pt];
        }
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    int ans = 0;

    for(int i=1; i<n; i++){
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs(1,1,0);

    if(n%2!=0){
        cout << -1 << endl;
        return 0;
    }

    for(int i=1;i<=n; i++)
        v[level[i]].pb(i);

    for(int i=maxx-1; i>=2; i--){
        for(int j=0; j<v[i].size(); j++){
            int pt = v[i][j];
            if(cnt[pt]%2 == 0){
                ans++;
                parent[pt] -=cnt[pt];
            }
        }
    }

    cout << ans << endl;
    return 0;
}


// http://codeforces.com/problemset/problem/982/C

// #include <bits/stdc++.h>
// using namespace std;

// #define ll long long
// #define eps 1e-10
// #define fi first
// #define se second
// #define MOD1 1000000007LL
// #define MOD 1000000009LL
// #define p1 53
// #define se second
// #define inf 20000000000LL
// #define pb push_back

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

// ll modx(ll base, ll ex)
// {
//     ll ans = 1LL, val = base;
//     while(ex > 0LL)
//     {
//         if(ex&1LL)
//             ans = (ans*val)%MOD;
//         val = (val*val)%MOD;
//         ex = ex>>1LL;
//     }
//     return ans;
// }

// const int maxn = 1e5 + 5;
// vector<int> adj[maxn], v[maxn];
// bool visit[maxn];
// int parent[maxn], level[maxn];
// int cnt[maxn];
// int n, m, x, y, maxx;

// void dfs(int start, int depth, int par){

//     visit[start] = true;
//     level[start] = depth;
//     parent[start] = par;
//     cnt[start] = 1;
//     maxx = max(maxx, depth);

//     for(int i=0; i<adj[start].size(); i++){
//         int pt = adj[start][i];

//         if(!visit[pt]){
//             dfs(pt, depth+1, start);
//             cnt[start]+=cnt[pt];
//         }
//     }
// }

// int main() {

//     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//     cin >> n;
//     int ans = 0;

//     for(int i=1; i<n; i++){
//         cin >> x >> y;
//         adj[x].pb(y);
//         adj[y].pb(x);
//     }

//     dfs(1,1,0);

//     if(n%2!=0){
//         cout << -1 << endl;
//         return 0;
//     }

//     for(int i=1;i<=n; i++)
//         v[level[i]].pb(i);

//     for(int i=maxx-1; i>=2; i--){
//         for(int j=0; j<v[i].size(); j++){
//             int pt = v[i][j];
//             if(cnt[pt]%2 == 0){
//                 ans++;
//                 parent[pt] -=cnt[pt];
//             }
//         }
//     }

//     cout << ans << endl;
//     return 0;
// }

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define eps 1e-10
#define fi first
#define se second
#define MOD1 1000000007LL
#define MOD 1000000009LL
#define p1 53
#define se second
#define inf 20000000000LL
#define pb push_back

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

ll modx(ll base, ll ex)
{
    ll ans = 1LL, val = base;
    while(ex > 0LL)
    {
        if(ex&1LL)
            ans = (ans*val)%MOD;
        val = (val*val)%MOD;
        ex = ex>>1LL;
    }
    return ans;
}

const int maxn = 1e5 + 5;
vector<int> adj[maxn], v[maxn];
bool visit[maxn];
int parent[maxn], level[maxn];
int cnt[maxn];
int n, m, x, y, maxx, ans;

void dfs(int start, int depth, int par){

    visit[start] = true;
    level[start] = depth;
    parent[start] = par;
    cnt[start] = 1;
    maxx = max(maxx, depth);

    for(int i=0; i<adj[start].size(); i++){
        int pt = adj[start][i];

        if(!visit[pt]){
            dfs(pt, depth+1, start);
            cnt[start]+=cnt[pt];
        }
    }

    if(cnt[start]%2 ==0)
        ans++;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for(int i=1; i<n; i++){
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs(1,1,0);

    if(n%2!=0){
        cout << -1 << endl;
        return 0;
    }

    cout << ans - 1 << endl;
    return 0;
}


// http://codeforces.com/problemset/problem/982/C

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define eps 1e-10
#define fi first
#define se second
#define MOD1 1000000007LL
#define MOD 998244353LL
#define p1 53
#define se second
#define inf 2000000000005LL
#define pb push_back
#define pii pair<int,int>
#define maxn 300005
#define mp make_pair

int gcd1(int a, int b) {
    if (a == 0)
        return b;
    return gcd1(b % a, a);
}

ll modx(ll base, ll ex)
{
    ll ans = 1LL, val = base;
    while(ex > 0LL)
    {
        if(ex&1LL)
            ans = (ans*val)%MOD;
        val = (val*val)%MOD;
        ex = ex>>1LL;
    }
    return ans;
}

int n;
vector<int> adj[maxn];
bool visit[maxn];
int sz[maxn];
int ans;

void dfs(int start) {

    visit[start] = true;
    sz[start] = 1;

    for (int i = 0; i < adj[start].size(); i++) {
        int pt = adj[start][i];
        if (!visit[pt]) {
            dfs(pt);
            sz[start] += sz[pt];
        }
    }

    if (sz[start] % 2 == 0 && start != 1)
        ans++;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    int u, v;
    for(int i = 1; i < n; i++) {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    if (n % 2) {
        cout << "-1" << endl;
        return 0;
    }

    dfs(1);

    cout << ans << endl;
    return 0;
}


// http://codeforces.com/problemset/problem/982/C

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define eps 1e-10
#define fi first
#define se second
#define MOD1 1000000007LL
#define MOD 998244353LL
#define p1 53
#define se second
#define inf 2000000000005LL
#define pb push_back
#define pii pair<int,int>
#define maxn 300005
#define mp make_pair

int gcd1(int a, int b) {
    if (a == 0)
        return b;
    return gcd1(b % a, a);
}

ll modx(ll base, ll ex)
{
    ll ans = 1LL, val = base;
    while(ex > 0LL)
    {
        if(ex&1LL)
            ans = (ans*val)%MOD;
        val = (val*val)%MOD;
        ex = ex>>1LL;
    }
    return ans;
}

int n;
vector<int> adj[maxn];
bool visit[maxn];
int sz[maxn];
vector<int> level[maxn];
int maxl;

void dfs(int start, int l) {

    visit[start] = true;
    sz[start] = 1;
    level[l].pb(start);
    maxl = max(maxl, l);

    for (int i = 0; i < adj[start].size(); i++) {
        int pt = adj[start][i];
        if (!visit[pt]) {
            dfs(pt, l + 1);
            sz[start] += sz[pt];
        }
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    int u, v;
    for(int i = 1; i < n; i++) {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    if (n % 2) {
        cout << "-1" << endl;
        return 0;
    }

    dfs(1, 1);

    int ans = 0;
    for (int i = maxl - 1; i >= 2; i--) {
        for (int j = 0; j < level[i].size(); j++) {
            int pt = level[i][j];
            if (sz[pt] % 2 == 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


// http://codeforces.com/problemset/problem/982/C

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define eps 1e-10
#define fi first
#define se second
#define MOD1 1000000007LL
#define MOD 998244353LL
#define p1 53
#define se second
#define inf 2000000000005LL
#define pb push_back
#define pii pair<int,int>
#define maxn 300005
#define mp make_pair

int gcd1(int a, int b) {
    if (a == 0)
        return b;
    return gcd1(b % a, a);
}

ll modx(ll base, ll ex)
{
    ll ans = 1LL, val = base;
    while(ex > 0LL)
    {
        if(ex&1LL)
            ans = (ans*val)%MOD;
        val = (val*val)%MOD;
        ex = ex>>1LL;
    }
    return ans;
}

int n;
vector<int> adj[maxn];
bool visit[maxn];
int sz[maxn];
int ans;

void dfs(int start) {

    visit[start] = true;
    sz[start] = 1;

    for (int i = 0; i < adj[start].size(); i++) {
        int pt = adj[start][i];
        if (!visit[pt]) {
            dfs(pt, l + 1);
            sz[start] += sz[pt];
        }
    }

    if (sz[start] % 2 == 0 && start != 1)
        ans++;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    int u, v;
    for(int i = 1; i < n; i++) {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    if (n % 2) {
        cout << "-1" << endl;
        return 0;
    }

    dfs(1);

    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa&&f[v][0]==INT_MIN)b[++cnt]=v;
	}
	if(cnt&1)
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][0]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][0]+=f[b[i]][1];
		f[u][1]=INT_MIN;
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][1]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][1]+=f[b[i]][1];
		f[u][0]=INT_MIN;
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v==fa)continue;
		if(f[v][0]==INT_MIN)b[++cnt]=v;
		else f[u][0]+=f[v][0]+1;
	}
	if(cnt)if(cnt&1)
	{
		For(i,1,cnt)f[u][0]+=f[b[cnt]][1];
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
		}
		f[u][1]=(mx==INT_MIN?mx:f[u][0]+mx);
	}
	else
	{
		f[u][1]=f[u][0];
		For(i,1,cnt)f[u][1]+=f[b[cnt]][1];
		f[u][0]=INT_MIN;
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			if(f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa&&f[v][0]==INT_MIN)b[++cnt]=v;
	}
	if(cnt)if(cnt&1)
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][0]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][0]+=f[b[i]][1];
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN&&f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
		}
		f[u][1]=(mx==INT_MIN?mx:f[u][0]+mx);
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][1]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][1]+=f[b[i]][1];
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN&&f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			if(f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa&&f[v][0]==INT_MIN)b[++cnt]=v;
	}
	if(cnt)if(cnt&1)
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][0]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][0]+=f[b[i]][1];
		f[u][1]=INT_MIN;
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN)f[u][1]+=f[v][0]+1;
		}
		For(i,1,cnt)f[u][1]+=f[b[i]][1];
		f[u][0]=INT_MIN;
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=INT_MIN;
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v==fa)continue;
		if(f[v][0]==INT_MIN)b[++cnt]=v;
		else f[u][0]+=f[v][0]+1;
	}
	if(cnt)if(cnt&1)
	{
		For(i,1,cnt)f[u][0]+=f[b[cnt]][1];
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN&&f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
		}
		f[u][1]=(mx==INT_MIN?mx:f[u][0]+mx);
	}
	else
	{
		f[u][1]=f[u][0];
		For(i,1,cnt)f[u][1]+=f[b[cnt]][1];
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v!=fa&&f[v][0]>INT_MIN&&f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
	else
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			if(f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v==fa)continue;
		if(f[v][0]==INT_MIN)b[++cnt]=v;
	}
	if(cnt)
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			f[u][0]+=Max(f[v][0]+1,0);
		}
		if(cnt&1)
		{
			For(i,1,cnt)f[u][0]+=f[b[cnt]][1];
			f[u][1]=INT_MIN;
		}
		else
		{
			f[u][1]=f[u][0];
			For(i,1,cnt)f[u][1]+=f[b[cnt]][1];
			f[u][0]=INT_MIN;
		}
	}
	else
	{
		int mx=INT_MIN;
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			if(f[v][1]>INT_MIN)mx=Max(mx,f[v][1]-f[v][0]-1);
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=(mx==INT_MIN?mx:f[u][1]+mx);
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],b[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,cnt=0;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v==fa)continue;
		if(f[v][0]==INT_MIN)b[++cnt]=v;
	}
	if(cnt)
	{
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			f[u][0]+=Max(f[v][0]+1,0);
		}
		if(cnt&1)
		{
			For(i,1,cnt)f[u][0]+=f[b[cnt]][1];
			f[u][1]=INT_MIN;
		}
		else
		{
			f[u][1]=f[u][0];
			For(i,1,cnt)f[u][1]+=f[b[cnt]][1];
			f[u][0]=INT_MIN;
		}
	}
	else
	{
		int mx=INT_MIN;
		for(i=head[u];i;i=e[i].next)
		{
			v=e[i].to;
			if(v==fa)continue;
			mx=Max(mx,f[v][1]-f[v][0]-1);
			f[u][1]+=f[v][0]+1;
		}
		f[u][0]=f[u][1]+mx;
	}
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][0],-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define Max(x,y)((x)>(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct node
{
	int next,to;
}e[200005];
int f[N][2],head[N],g;
int read()
{
	int A;
	bool K;
	char C;
	C=A=K=0;
	while(C<'0'||C>'9')K|=C=='-',C=getchar();
	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
	return(K?-A:A);
}
inline void add(int u,int v)
{
	e[++g].to=v;
	e[g].next=head[u];
	head[u]=g;
}
void dp(int u,int fa)
{
	int i,v,mx=INT_MIN;
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v!=fa)dp(v,u);
	}
	for(i=head[u];i;i=e[i].next)
	{
		v=e[i].to;
		if(v==fa)continue;
		mx=Max(mx,f[v][0]-f[v][1]-1);
		f[u][0]+=f[v][1]+1;
	}
	f[u][1]=f[u][0]+mx;
}
int main()
{
	int n,i,u,v;
	n=read();
	For(i,1,n-1)
	{
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	dp(1,0);
	cout<<Max(f[1][1],-1);
	return 0;
}


//982C	--1500
#include <iostream>
#include <map>
#include <set>
std::map< int, std::set< int > > m;
int n, u, v, ans;
bool was[100007];

int make(std::set<int> &s, int it) {
	if (was[it]) {
		return 0;
	}
	s.insert(it);
	was[it] = true;
	int rez = 0;
	for (int el : m[it]) {
		rez += make(s, el) + 1;
		s.insert(el);
	}
	return rez;
}
int main() {
	std::cin >> n;
	for (int i = 1; i < n; ++i) {
		std::cin >> u >> v;
		m[v].insert(u);
		m[u].insert(v);
	}
	for (int i = 1; i <= n; ++i) {
		if (!was[i]) {
			std::set< int > s;
			int rbr = make(s, i) / 2, p;
			if (s.size() % 2) {
				std::cout << -1;
				return 0;
			}
			p = s.size();
			if (p != 2) {
				for (int el : s) {
					if (m[el].size() == 1) {
						--rbr;
						--p;
					}
				}
				rbr += 2;
				p += 2;
				if (rbr - p / 2 > 0) {
					ans += rbr - p / 2;
				}
			}
		}
	}
	std::cout << ans;
}


//982C	--1500
#include <iostream>
#include <map>
#include <set>
std::map< int, std::set< int > > m;
int n, u, v, ans;
bool was[100007];

int make(std::set<int> &s, int it) {
	if (was[it]) {
		return 0;
	}
	s.insert(it);
	was[it] = true;
	int rez = 0;
	for (int el : m[it]) {
		rez += make(s, el) + 1;
		s.insert(el);
	}
	return rez;
}
int main() {
	std::cin >> n;
	for (int i = 1; i < n; ++i) {
		std::cin >> u >> v;
		m[v].insert(u);
		m[u].insert(v);
	}
	for (int i = 1; i <= n; ++i) {
		if (!was[i]) {
			std::set< int > s;
			int rbr = make(s, i) / 2;
			if (s.size() % 2) {
				std::cout << -1;
				return 0;
			}
			ans += rbr - s.size() / 2;
		}
	}
	std::cout << ans;
}


//982C	--1500
#include <iostream>
#include <map>
#include <set>
std::map< int, std::set< int > > m;
int n, u, v, ans;
bool was[100007];

int make(std::set<int> &s, int it) {
	if (was[it]) {
		return 0;
	}
	was[it] = true;
	int rez = 0;
	for (int el : m[it]) {
		rez += make(s, el) + 1;
		s.insert(el);
	}
	return rez;
}
int main() {
	std::cin >> n;
	for (int i = 1; i < n; ++i) {
		std::cin >> u >> v;
		m[v].insert(u);
		m[u].insert(v);
	}
	for (int i = 1; i <= n; ++i) {
		if (!was[i]) {
			std::set< int > s;
			int rbr = make(s, i) / 2;
			if (s.size() % 2) {
				std::cout << -1;
				return 0;
			}
			ans += rbr - s.size() / 2;
		}
	}
	std::cout << ans;
}


//982C	--1500
#include <iostream>
#include <map>
#include <set>
std::map< int, std::set< int > > m;
int n, u, v, ans;
bool was[100007];

int make(std::set<int> &s, int it) {
	if (was[it]) {
		return 0;
	}
	s.insert(it);
	was[it] = true;
	int rez = 0;
	for (int el : m[it]) {
		rez += make(s, el) + 1;
		s.insert(el);
	}
	return rez;
}
int main() {
	std::cin >> n;
	for (int i = 1; i < n; ++i) {
		std::cin >> u >> v;
		m[v].insert(u);
		m[u].insert(v);
	}
	for (int i = 1; i <= n; ++i) {
		if (!was[i]) {
			std::set< int > s;
			int rbr = make(s, i) / 2, p;
			if (s.size() % 2) {
				std::cout << -1;
				return 0;
			}
			p = s.size();
			for (int el : s) {
				if (m[el].size() == 1) {
					--rbr;
					--p;
				}
			}
			if (rbr - p / 2 > 0) {
				ans += rbr - p / 2;
			}
		}
	}
	std::cout << ans;
}


//982C	--1500
#include <iostream>
#include <map>
#include <set>

std::map< int, std::set< int > > m;
int n, u, v, ans;
bool was[100007];

int make(int it) {
	was[it] = true;
	int rez = 1;
	for (auto el : m[it]) {
		if (!was[el]) {
			rez += make(el);
		}
	}
	if (rez % 2 == 0) {
		++ans;
		return 0;
	}
	return 1;
}
int main() {
	std::cin >> n;
	for (int i = 1; i < n; ++i) {
		std::cin >> u >> v;
		m[v].insert(u);
		m[u].insert(v);
	}

	std::cout << (make(1) % 2 ? -1 : ans-1);
}


// BIG WA
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define MOD 1000000007
#define lp(i,n) for(int i = 0;i < n;++i)
#define sz(x) ((int)(x).size())

typedef  long long ll;
typedef pair<ll , ll> pii;
typedef  double ld;
typedef vector<int> vi;
typedef unsigned long long ull ;
static const int OO = 0x3f3f3f3f , N =3*1e5 + 10 ; static const long long OOL = 0x3f3f3f3f3f3f3f3fLL;

int a , b , en , n , ans;
vi vec[N];

void Dfs(int u = en,int pr = -1,int len = 1){

    lp(i,sz(vec[u])){
        int child = vec[u][i];
        if(pr!=child){
            if(len == 2)ans++,Dfs(child , u , 1);
            else Dfs(child ,u, len+1);
        }
    }

}

int main (){
    cin >> n;
    lp(i,n-1){
        cin >> a >> b;
        vec[a].pb(b);
        vec[b].pb(a);

    }
    lp(i,n){
        if(sz(vec[i+1]) == 1){
            en = i+1;
            break;
        }
    }
    if(n % 2)
    {
        return cout << -1,0;
    }
    Dfs();
    cout << ans ;

}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define MOD 1000000007
#define lp(i,n) for(int i = 0;i < n;++i)
#define sz(x) ((int)(x).size())

typedef  long long ll;
typedef pair<ll , ll> pii;
typedef  double ld;
typedef unsigned long long ull ;
static const int OO = 0x3f3f3f3f , N =2*1e5 + 10 ; static const long long OOL = 0x3f3f3f3f3f3f3f3fLL;

int dx[] = {1 , 1 , 0 , 0 , -1 , -1 , -1 , 1};
int dy[] = {1 , 0 , 1 , -1 , 0 , -1 , 1 , -1};
int n,v,u , tot[N],ans;
vector<int>vec[N];
void solve(int i , int parent){
    tot[i]++;
    lp(j,sz(vec[i])){
        if(vec[i][j]!=parent){
            solve(vec[i][j],i);
            if(tot[vec[i][j]]%2)tot[i]++;
            else ans++;
        }
    }
}
int main (){
    cin >> n;

    lp(i,n-1){
    cin >> u >> v;
    vec[u].pb(v);
    vec[v].pb(u);
    }
    if(n%2)return cout << -1,0;
    solve(1,-1);
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define MOD 1000000007
#define lp(i,n) for(int i = 0;i < n;++i)
#define sz(x) ((int)(x).size())

typedef  long long ll;
typedef pair<ll , ll> pii;
typedef  double ld;
typedef vector<int> vi;
typedef unsigned long long ull ;
static const int OO = 0x3f3f3f3f , N =3*1e5 + 10 ; static const long long OOL = 0x3f3f3f3f3f3f3f3fLL;

int a , b , en , n , ans;
vi vec[N];
bool vis[N];
void Dfs(int u = 1,int pr = -1,int len = 1){

    vis[u]=1;
    lp(i,sz(vec[u])){
        int child = vec[u][i];
        if(!vis[child]){
            if(len%2==0)ans++,Dfs(child,u , 1);
            else Dfs(child ,u, len+1);
        }
    }

}

int main (){
    cin >> n;
    lp(i,n-1){
        cin >> a >> b;
        vec[a].pb(b);
        vec[b].pb(a);

    }
    if(n % 2)
    {
        return cout << -1,0;
    }
    Dfs();
    cout << ans ;

}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define MOD 1000000007
#define lp(i,n) for(int i = 0;i < n;++i)
#define sz(x) ((int)(x).size())

typedef  long long ll;
typedef pair<ll , ll> pii;
typedef  double ld;
typedef vector<int> vi;
typedef unsigned long long ull ;
static const int OO = 0x3f3f3f3f , N =3*1e5 + 10 ; static const long long OOL = 0x3f3f3f3f3f3f3f3fLL;

int a , b , en , n , ans;
vi vec[N];

void Dfs(int u = 1,int pr = -1,int len = 1){

    lp(i,sz(vec[u])){
        int child = vec[u][i];
        if(pr!=child){
            if(len%2==0)ans++,Dfs(child,u , 1);
            else Dfs(child ,u, len+1);
        }
    }

}

int main (){
    cin >> n;
    lp(i,n-1){
        cin >> a >> b;
        vec[a].pb(b);
        vec[b].pb(a);

    }
    if(n % 2)
    {
        return cout << -1,0;
    }
    Dfs();
    cout << ans ;

}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005, M = 200005;
int n, m, idx, ans;
int to[M], ne[M], h[N];
void add(int u, int v)
{
	to[idx] = v, ne[idx] = h[u], h[u] = idx ++ ;
}

int dfs(int u, int fa)
{
	int node_s = 1, cnt = 0;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = to[i];
		if(j != fa)
		{
			cnt ++;
			node_s += dfs(j, u);
		}
	}
	if(cnt == 0)	return 1;
	if(node_s % 2 == 0)	ans ++ ;
	return node_s;
}

int main()
{
	int u, v;
	memset(h, -1, sizeof(h));
	cin >> n;
	if(n == 1)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i ++ )
	{
		cin >> u >> v;
		add(u, v);
		add(v, u);
	}
	dfs(u, -1);
	cout << ans - 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005, M = 200005;
int n, m, idx, ans;
int to[M], ne[M], h[N];
void add(int u, int v)
{
	to[idx] = v, ne[idx] = h[u], h[u] = idx ++ ;
}

int dfs(int u, int fa)
{
	int node_s = 1, cnt = 0;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = to[i];
		if(j != fa)
		{
			cnt ++;
			node_s += dfs(j, u);
		}
	}
	if(cnt == 0)	return 1;
	if(node_s % 2 == 0)	ans ++ ;
	return node_s;
}

int main()
{
	int u, v;
	memset(h, -1, sizeof(h));
	cin >> n;
	for(int i = 0; i < n - 1; i ++ )
	{
		cin >> u >> v;
		add(u, v);
		add(v, u);
	}
	dfs(u, -1);
	cout << ans - 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005, M = 200005;
int n, idx, ans;
int to[M], ne[M], h[N];
void add(int u, int v)
{
	to[idx] = v, ne[idx] = h[u], h[u] = idx ++ ;
}

int dfs(int u, int fa)
{
	int node_s = 1, cnt = 0;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = to[i];
		if(j != fa)
		{
			cnt ++;
			node_s += dfs(j, u);
		}
	}
	if(cnt == 0)	return 1;
	if(node_s % 2 == 0)	ans ++ ;
	return node_s;
}

int main()
{
	int u, v;
	memset(h, -1, sizeof(h));
	cin >> n;
	if(n & 1 == 1)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i ++ )
	{
		cin >> u >> v;
		add(u, v), add(v, u);
	}
	dfs(u, -1);
	cout << ans - 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005, M = 200005;
int n, idx, ans;
int to[M], ne[M], h[N], cnt[N];
void add(int u, int v)
{
	to[idx] = v, ne[idx] = h[u], h[u] = idx ++ ;
}

int dfs(int u, int fa)
{
	int node_s = 1, cnt = 0;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = to[i];
		if(j != fa)
		{
			cnt ++;
			node_s += dfs(j, u);
		}
	}
	if(cnt == 0)	return 1;
	if(node_s % 2 == 0)	ans ++ ;
	return node_s;
}

int cal_root()
{
	int res = 0, id;
	for(int i = 1; i <= n; i ++ )
		if(res < cnt[i])
			id = i, res = cnt[i];
	return id;
}
int main()
{
	int u, v;
	memset(h, -1, sizeof(h));
	cin >> n;
	if(n == 1)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i ++ )
	{
		cin >> u >> v;
		cnt[u] ++, cnt[v] ++;
		add(u, v), add(v, u);
	}
	dfs(cal_root(), -1);
	cout << ans - 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005, M = 200005;
int n, idx, ans;
int to[M], ne[M], h[N], cnt[N];
void add(int u, int v)
{
	to[idx] = v, ne[idx] = h[u], h[u] = idx ++ ;
}

int dfs(int u, int fa)
{
	int node_s = 1, cnt = 0;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = to[i];
		if(j != fa)
		{
			cnt ++;
			node_s += dfs(j, u);
		}
	}
	if(cnt == 0)	return 1;
	if(node_s % 2 == 0)	ans ++ ;
	return node_s;
}

int cal_root()
{
	int res = 0, id;
	for(int i = 1; i <= n; i ++ )
		if(res < cnt[i])
			id = i, res = cnt[i];
	return id;
}
int main()
{
	int u, v;
	memset(h, -1, sizeof(h));
	cin >> n;
	if(n & 1 == 1)
	{
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i ++ )
	{
		cin >> u >> v;
		cnt[u] ++, cnt[v] ++;
		add(u, v), add(v, u);
	}
	dfs(cal_root(), -1);
	cout << ans - 1 << endl;
	return 0;
}


// Harry Potter
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
int ch[N],n,a,i,j;
vector <int> d[N];
void dfs(int v,int p=-1){
	for(auto u:d[v])
		if (p!=u) dfs(u,v);
	if (ch[v]%2&&p!=-1) {a++;ch[v]=-1;}
	if (p==-1&&!(ch[v]%2)) a=-1;
	ch[p]+=ch[v]+1;
}
int main(){
	for(scanf("%d", &n);--n;){
		scanf("%d%d", &i,&j);
		d[j].push_back(i);
		d[i].push_back(j);}
	dfs(1); cout<<a;
}


// Harry Potter
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
int child[N], n, ans;
bool used[N];
vector <int> adj[N];
void dfs(int v, int p = -1){
	used[v] = 1;
	for(int i = 0; i < adj[v].size(); i ++){
		int u = adj[v][i];
		if (!used[u]){
			dfs(u, v);
		}
	}
	if (child[v] % 2 && p != -1) {ans ++; child[v] = -1;}
	if (p == -1 && child[v] % 2 == 0) {cout << -1; exit(0);}
	child[p] += child[v] + 1;
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n; int k = n;
	while(--k){
		int u, v;cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	cout << ans;
}
/*
7
1 2
2 3
3 5
2 4
1 6
6 7

4
1 2
1 3
1 4
*/


// Harry Potter
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
int ch[N],n,a,i,j;
vector <int> d[N];
void dfs(int v,int p=-1){
	for(auto u:d[v])
		if (p!=u) dfs(u,v);
	if (ch[v]&1&&p!=-1) {a++;ch[v]=-1;}
	if (p==-1&&ch[v]&1^1) a=-1;
	ch[p]+=ch[v]+1;
}
int main(){
	for(scanf("%d", &n);--n;){
		scanf("%d%d", &i,&j);
		d[j].push_back(i);
		d[i].push_back(j);}
	dfs(1); cout<<a;
}


// Harry Potter
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
bool used[N];
int ans;
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	int k = n;
	while(--k){
		int u, v; cin >> u >> v;
		if (!used[u] && !used[v]) ans ++, used[u] = used[v] = 1;
	}
	for(int i = 1; i <= n; i ++) if (!used[i]) return cout << -1, 0;
	cout << n - ans - 1;
}
/*
4
2 4
4 1
3 1
*/


// Harry Potter
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
int ch[N],n,a,i;
vector <int> adj[N];
void dfs(int v,int p=-1){
	for(auto u : adj[v])
		if (p!=u) dfs(u,v);
	if (ch[v]%2&&p!=-1) {a++;ch[v]=-1;}
	if (p==-1&&!(ch[v]%2)) a=-1;
	ch[p]+=ch[v]+1;
}
int main(){
	for(scanf("%d", &n);--n;){
		int u,v;cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	cout<<a;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;

  REP(i, 1, N - 1) { cin >> x >> y; }
  if (N & 1)
    cout << -1 << endl;
  else
    cout << N / 2 - 1 << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

void CutTree(map<int, set<int>> &NB, int &etr) {
  // check if the remaining graph is a line or not
  bool isline = true;
  for (auto nd : NB) {
    if (nd.second.size() > 2)
      isline = false;
  }
  if (isline) {
    etr += NB.size() / 2 - 1;
    NB.clear();
  } else {
    // find all leaf
    set<int> Leaf, Cent;
    for (auto nd : NB) {
      if (nd.second.size() == 1)
        Leaf.insert(nd.first);
    }
    // Process the leaves
    for (auto e : Leaf) {
      int child = e, parent = *(NB[child].begin());
      while ((NB[child].size() == 1) && (NB[parent].size() == 2)) {
        etr++;
        NB.erase(child);
        NB[parent].erase(child);
        child = *(NB[parent].begin());
        NB.erase(parent);
        NB[child].erase(parent);
        parent = *(NB[child].begin());
      }
    }
    // Merge the leaves
    for (auto nd : NB) {
      if (nd.second.size() > 1)
        Cent.insert(nd.first);
    }
    for (auto n : Cent) {
      vector<int> CentLeaf;
      for (auto d : NB[n])
        if (NB[d].size() == 1)
          CentLeaf.PB(d);
      for (size_t i = 0; i < CentLeaf.size() / 2; i++) {
        NB[n].erase(CentLeaf[2 * i]);
        NB[n].erase(CentLeaf[2 * i + 1]);
        NB.erase(CentLeaf[2 * i]);
        NB.erase(CentLeaf[2 * i + 1]);
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  map<int, set<int>> NB;

  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
  if (N & 1)
    cout << -1 << endl;
  else {
    int etr = 0;
    while (!NB.empty())
      CutTree(NB, etr);
    cout << etr << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

map<int, set<int>> NB;
vector<int> ns;
void szSubtree(int s, int p) {
  ns[s] = 1;
  for (auto n : NB[s]) {
    if (n == p)
      continue;
    szSubtree(n, s);
    ns[s] += ns[n];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  REP(i, 0, N) ns.PB(1);
  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
  szSubtree(1, 0); // set "1" to be the root
  int res = 0;
  for (int i = 2; i < N; i++) {
    if (ns[i] % 2 == 0)
      res++;
  }
  cout<<res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

map<int, set<int>> NB;
vector<int> ns;
void szSubtree(int s, int p) {
  ns[s] = 1;
  for (auto n : NB[s]) {
    if (n == p)
      continue;
    szSubtree(n, s);
    ns[s] += ns[n];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  REP(i, 0, N) ns.PB(1);
  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
  szSubtree(1, 0); // set "1" to be the root
  int res = 0;
  for (int i = 2; i <= N; i++) {
    if (ns[i] % 2 == 0)
      res++;
  }
if (res ==0)
cout << -1 << endl;
else
  cout << res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

map<int, set<int>> NB;
vector<int> ns;
void szSubtree(int s, int p) {
  ns[s] = 1;
  for (auto n : NB[s]) {
    if (n == p)
      continue;
    szSubtree(n, s);
    ns[s] += ns[n];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  REP(i, 0, N) ns.PB(1);
  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
  szSubtree(1, 0); // set "1" to be the root
  int res = 0;
  for (int i = 2; i <= N; i++) {
    if (ns[i] % 2 == 0)
      res++;
  }
  cout << res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

map<int, set<int>> NB;
vector<int> ns;
void szSubtree(int s, int p) {
  ns[s] = 1;
  for (auto n : NB[s]) {
    if (n == p)
      continue;
    szSubtree(n, s);
    ns[s] += ns[n];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  REP(i, 0, N) ns.PB(1);
  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
  szSubtree(1, 0); // set "1" to be the root
  int res = 0;
  for (int i = 2; i < N; i++) {
    if (ns[i] % 2 == 0)
      res++;
  }
  cout res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007

map<int, set<int>> NB;
vector<int> ns;
void szSubtree(int s, int p) {
  ns[s] = 1;
  for (auto n : NB[s]) {
    if (n == p)
      continue;
    szSubtree(n, s);
    ns[s] += ns[n];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, x, y;
  cin >> N;
  REP(i, 0, N) ns.PB(1);
  REP(i, 1, N - 1) {
    cin >> x >> y;
    NB[x].insert(y);
    NB[y].insert(x);
  }
if (N&1)
cout << -1 << endl;
else {
  szSubtree(1, 0); // set "1" to be the root
  int res = 0;
  for (int i = 2; i <= N; i++) {
    if (ns[i] % 2 == 0)
      res++;
  }
  cout << res << endl;
}
  return 0;
}