#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int m=100007;
const int i=1e9+7;
int n,r,s;
int h[m],p[m];
int d[m][2][2][2][2];
vector<int> v[m];
int f(int x)
{
if(x==h[x])
{
return x;
}
int t=f(h[x]);
return h[x]=t;
}
void f(int x,int y)
{
p[x]=y;
for(int j=0;j<(int)v[x].size();j++)
{
int z=v[x][j];
if(z==y)
{
continue;
}
f(z,x);
}
}
int f(int x,int a,int b,int c,int e)
{
if(d[x][a][b][c][e]!=-1)
{
return d[x][a][b][c][e];
}
ll g=i;
bool k=1;
if(x==r&&a!=c)
{
k=0;
}
if(x==s&&a!=e)
{
k=0;
}
if(x==s&&b&&c)
{
k=0;
}
if(!k)
{
return d[x][a][b][c][e]=i;
}
bool q=(b||(x==r&&e)||(x==s&&c));
ll l=a;
for(auto z:v[x])
{
if(z==p[x])
{
continue;
}
l+=f(z,0,a,c,e);
}
if(q)
{
g=min(g,l);
}
else
{
for(auto z:v[x])
{
if(z==p[x])
{
continue;
}
ll w=l-f(z,0,a,c,e)+f(z,1,a,c,e);
if(w<g)
{
g=w;
}
}
}
return d[x][a][b][c][e]=(int)g;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
memset(d,-1,sizeof(d));
if(!(cin>>n))
{
return 0;
}
for(int j=1;j<=n;j++)
{
h[j]=j;
}
for(int j=0;j<n;j++)
{
int x,y;
cin>>x>>y;
int u=f(x);
int t=f(y);
if(u==t)
{
r=x;
s=y;
}
else
{
h[u]=t;
v[x].push_back(y);
v[y].push_back(x);
}
}
f(r,0);
ll o=i;
for(int c=0;c<=1;c++)
{
for(int e=0;e<=1;e++)
{
ll res=f(r,c,0,c,e);
if(res<o)
{
o=res;
}
}
}
if(o>=i)
{
cout<<-1<<endl;
}
else
{
cout<<o<<endl;
}
return 0;
}