/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=3;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
   if(ind!=-1)
   {
    for(ll i=0;i<n-1;i++)
    {
       if((vect1[i].first==ind || vect1[i].second==ind)&& c<3)
       {
               cout<<c++<<ln;
        }
        else
       {
               cout<<val1<<ln;
               val1++;
       }
    }
   }
   else
   {
       for(ll i=0;i<n-1;i++)
       {
           cout<<i<<ln;
       }
   }
    return 0;
}


/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=n-2;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
    for(ll i=0;i<n-1;i++)
    {
       if(vect1[i].first==ind || vect1[i].second==ind)
       {
           if(c<3)
           {
               cout<<val2<<ln;
               val2++;
           }
           else
           {
               cout<<val1<<ln;
               val1--;
           }
           c++;
       }
       else
       {
           cout<<val1<<ln;
           val1--;
       }
    }
    return 0;
}


/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=n-2;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
   if(ind!=-1)
   {
    for(ll i=0;i<n-1;i++)
    {
       if((vect1[i].first==ind || vect1[i].second==ind)&& c<3)
       {
               cout<<c++<<ln;
        }
        else
       {
               cout<<val1<<ln;
               val1--;
       }
    }
   }
   else
   {
       for(ll i=0;i<n-1;i++)
       {
           cout<<val1<<ln;
           val1--;
       }
   }
    return 0;
}


/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=n-2;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
   if(ind!=-1)
   {
    for(ll i=0;i<n-1;i++)
    {
       if(vect1[i].first==ind || vect1[i].second==ind)
       {
           if(c<3)
           {
               cout<<val2<<ln;
               val2++;
           }
           else
           {
               cout<<val1<<ln;
               val1--;
           }
           c++;
       }
       else
       {
           cout<<val1<<ln;
           val1--;
       }
    }
   }
   else
   {
       for(ll i=0;i<n-1;i++)
       {
           cout<<val1<<ln;
           val1--;
       }
   }
    return 0;
}


/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=n-2;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
    for(ll i=0;i<n-1;i++)
    {
       if(vect1[i].first==ind || vect1[i].second==ind && ind!=-1)
       {
           if(c<3)
           {
               cout<<val2<<ln;
               val2++;
           }
           else
           {
               cout<<val1<<ln;
               val1--;
           }
           c++;
       }
       else
       {
           cout<<val1<<ln;
           val1--;
       }
    }
    return 0;
}


/* viper_mark | Aman kumar singh | On project baigan bharta. */
#include <bits/stdc++.h>
#define fast_inou ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pll pair<ll,ll>
#define mod 1000000007
#define ln "\n"
#define ll long long
#define mr make_pair
#define pb push_back
using namespace std;
int main()
{
    fast_inou
    ll n;
    cin>>n;
    vector<ll> vect[n+1];
    vector<pll> vect1;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        vect1.pb({x,y});
        vect[x].pb(y);
        vect[y].pb(x);
    }
    ll ind=-1;
    for(ll i=1;i<=n;i++)
    {
        if(vect[i].size()>=3)
        {
            ind=i;
            break;
        }
    }
    ll val1=3;
    ll val2=0;
    ll c=0;
   // cout<<ind<<ln;
   if(ind!=-1)
   {
    for(ll i=0;i<n-1;i++)
    {
       if((vect1[i].first==ind || vect1[i].second==ind)&& c<3)
       {
               cout<<c++<<ln;
        }
        else
       {
               cout<<val1<<ln;
               val1++;
       }
    }
   }
   else
   {
       for(ll i=0;i<n-1;i++)
       {
           cout<<i<<ln;
       }
   }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll n ;
const ll maxx = 1e5 + 5 ;
vl v[maxx] ;
ll ans[maxx] ;

map<pair<ll,ll> , ll > mpp ;

vl res;

ll deg[maxx] ;
ll st;

int main()
{
    //ios;
    cin >> n ;
    st= 0;

    forn(i , 1 , n - 1 ) {
       ll x , y;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
       ++deg[x];
       ++deg[y] ;
       mpp[{x , y}] = i ;
       mpp[{y , x}] = i ;

    }
    memset(ans , -1 ,so ans) ;
    st = 0 ;
    forn(i , 1 , n ) {
       if(v[i].size() >= 3){
        for(auto x : v[i]){
            ll ind = mpp[{i , x}] ;
            ans[ind] = st++ ;
        }
        br ;
       }
    }
    forn(i , 1 , n - 1 ){
       if(ans[i] == -1){
        ans[i] = st++;
       }
    }
    forn(i , 1 , n - 1 ) {
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll n ;
const ll maxx = 1e5 + 5 ;
vl v[maxx] ;
ll ans[maxx] ;

map<pair<ll,ll> , ll > mpp ;

vl res;

ll deg[maxx] ;
ll st;
void dfs(ll curr , ll par)
{
    for(auto x : v[curr]){
        if(x == par) con ;
        dfs(x , curr) ;
    }
    if(deg[curr] == 1){
        if(par != -1){
            ll ind = mpp[{curr , par}] ;
            ans[ind] = st++ ;
        }
    }
}

int main()
{
    //ios;
    cin >> n ;
    st= 0;

    forn(i , 1 , n - 1 ) {
       ll x , y;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
       ++deg[x];
       ++deg[y] ;
       mpp[{x , y}] = i ;
       mpp[{y , x}] = i ;

    }
    memset(ans , -1 ,so ans) ;
    dfs(1 , -1) ;
    forn(i , 1 , n - 1 ) {
       if(ans[i] == -1){
        ans[i] = st++ ;
       }
    }
    forn(i , 1 , n - 1 ) {
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll n ;
const ll maxx = 1e5 + 5 ;
vl v[maxx] ;
ll ans[maxx] ;

map<pair<ll,ll> , ll > mpp ;

vl res;

ll deg[maxx] ;
ll st;

int main()
{
    //ios;
    cin >> n ;
    st= 0;

    forn(i , 1 , n - 1 ) {
       ll x , y;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
       ++deg[x];
       ++deg[y] ;
       mpp[{x , y}] = i ;
       mpp[{y , x}] = i ;

    }
    memset(ans , -1 ,so ans) ;
    st = 0 ;
    forn(i , 1 , n ) {
       if(deg[i] >= 3){
        for(auto x : v[i]){
            ll ind = mpp[{i , x}] ;
            ans[ind] = st++ ;
        }
       }
    }
    forn(i , 1 , n - 1 ){
       if(ans[i] == -1){
        ans[i] = st++;
       }
    }
    forn(i , 1 , n - 1 ) {
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll n ;
const ll maxx = 1e5 + 5 ;
vl v[maxx] ;
ll ans[maxx] ;

map<pair<ll,ll> , ll > mpp ;

vl res;

ll deg[maxx] ;
ll st;

int main()
{
    //ios;
    cin >> n ;
    st= 0;

    forn(i , 1 , n - 1 ) {
       ll x , y;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
       ++deg[x];
       ++deg[y] ;
       mpp[{x , y}] = i ;
       mpp[{y , x}] = i ;

    }
    memset(ans , -1 ,so ans) ;
    st = 0 ;
    forn(i , 1 , n ) {
       if(v[i].size() >= 3){
        for(auto x : v[i]){
            ll ind = mpp[{i , x}] ;
            ans[ind] = st++ ;
        }

       }
    }
    forn(i , 1 , n - 1 ){
       if(ans[i] == -1){
        ans[i] = st++;
       }
    }
    forn(i , 1 , n - 1 ) {
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll n ;
const ll maxx = 1e5 + 5 ;
vl v[maxx] ;
ll ans[maxx] ;
ll st ;

vll foo ;

void dfs(ll curr , ll par)
{
    if(par != -1){
        foo.pb({curr , par}) ;
    }
    for(auto  x  : v[curr]){
        if(x == par) con ;
        dfs(x , curr) ;
    }
}
map<pair<ll,ll> , ll > mpp ;

vl res;
int main()
{
    //ios;
    cin >> n ;

    forn(i , 1 , n - 1 ) {
       ll x , y;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
       mpp[{x , y}] = i ;
       mpp[{y , x}] = i ;

    }
    st = n - 2 ;
    forn(i , 0 ,  n-  2 ){
       res.pb(i) ;
    }
    dfs(1 , -1) ;
    ll turn = 0 ;
    ll i = 0 , j = res.sz - 1;
    for(auto x : foo){
        ll ind = mpp[{x.fi , x.se}];
        if(turn == 0){
            ans[ind] = res[i++];
            turn = 1;
        }
        else{
            ans[ind] = res[j--];
            turn = 0 ;
        }
    }
    forn(i , 1 , n - 1 ){
       cout << ans[i] << " " ;
    }
    cout << el ;
    ro ;

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll u , v;
    cin >> u >> v;
    if((v - u)  < 0 ){
        cout << -1 << el ;
        ro;
    }
    if(u == v){
        if(u == 0){
            cout << 0 << el;
            ro ;
        }
        else {
            cout << 1 << el ;
            cout << u << el ;
            ro ;
        }
    }
    /// try to make a length of 2
    if((v - u) % 2 != 0){
          cout << -1 << el ;
          ro ;
    }
    /// try to make a length of 2
    ll z = (v - u) / 2;
    bool can = true ;
    ll ansa = 0 , ansb = 0 ;
    for(ll i = 60 ; i >= 0 ; --i){
        ll z_and = z & (1LL << i) ;
        ll u_or  = u & (1LL << i) ;
        if(z_and != 0 and u_or != 0){
            can = false;
            br ;
        }
    }
    if(can == true){
        for(ll i = 60 ; i >= 0 ; --i){
            ll z_and = z & (1LL << i) ;
            ll u_or  = u & (1LL << i) ;
            if(z_and == 0 and u_or == 0){
                con ;
            }
            if(z_and == 0 and u_or != 0){
                ansb|=(1LL << i);
            }
            if(z_and != 0 and u_or == 0){
                ansa|=(1LL << i);
                ansb|=(1LL << i) ;
            }
        }
        cout << 2 << el ;
        cout << ansa << " " << ansb << el ;
        ro;
    }
    else if(can == false){
        cout << 3 << el ;
        ll x = (v - u ) / 2;
        cout << u << " " << x << " " << x << el ;
        ro ;
    }

}


#include <bits/stdc++.h>

#define x first
#define y second
using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
map<pii, int> mp;
pii edge[NN];
int n;
int father[NN], vst[NN];
set<int> num;
int cnt=0;
vector<int> adj[NN];
int a, b;
int ans[NN];

int dfs(int u, int pre=-1) {
	father[u]=pre;
	vst[u]=1;
	if (adj[u].size()==1 and adj[u][0]==pre) return u;
	for (auto v : adj[u]) {
		if (vst[v]) continue;
		return dfs(v, u);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=1; i<n-1; i++) num.insert(i);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i]=pii(u,v);
		adj[u].push_back(v), adj[v].push_back(u);
	}
	a=dfs(1), b=dfs(1);
	for (int i=1; i<n; i++) {
		int x=edge[i].x, y=edge[i].y;
		if (x==a or y==a) {ans[i]=0; continue;}
		if (x==b or y==b) {ans[i]=n-2; continue;}
	}
	num.erase(1);
	for (int i=1; i<n; i++) {
		int x=edge[i].x, y=edge[i].y;
		if (vst[x] and vst[y]) { ans[i]=*num.begin(); if (num.size()) num.erase(num.begin());}
	}
	num.insert(1);
	for (int i=1; i<n; i++) {
		if (ans[i]) cout<<ans[i]<<endl;
		else {
			{cout<<*num.begin()<<endl; if (num.size()) num.erase(num.begin());}
		}
	}
	return 0;
}


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

typedef long long INT;
typedef pair<int, int> pii;

map<pii, int> ans;
map<pii, bool> vst;

int u[NN], v[NN];

vector<int> adj[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		scanf("%d%d", &u[i], &v[i]);
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	int nn = 0;

	if(n == 2) {puts("0");  return 0;}

	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1) {
			ans[pii(i, adj[i][0])] = ans[pii(adj[i][0], i)] = nn++;
			vst[pii(i, adj[i][0])] = vst[pii(adj[i][0], i)] = 1;
		}
	}

	for(int i = 1; i < n; i++){
		if(vst[pii(u[i], v[i])] == 0) printf("%d\n", nn++);
		else printf("%d\n", ans[pii(u[i], v[i])]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long INT;
typedef pair<int,int> pii;

const int NN=100010;
const int inf=0x3f3f3f3f;

vector<int> adj[NN];
map<pii,int> mp;
int ans[NN];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	int n,u,v;
	cin>>n;
	memset(ans,-1,sizeof ans);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
		mp[{u,v}]=i;
		mp[{v,u}]=i;
	}

	int vx=-1,num=0;
	for(int u=1;u<=n;u++){
		if(adj[u].size()>=3){
			vx=u;
			for(int v:adj[u]){
				ans[mp[{u,v}]]=num;
				ans[mp[{v,u}]]=num++;
			}
			break;
		}
	}

	for(int i=1;i<n;i++){
		if(ans[i]==-1)cout<<num++<<endl;
		else cout<<ans[i]<<endl;
	}

	return 0;
}


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

typedef long long INT;
typedef pair<int, int> pii;

queue <int> que;
bool vst[NN];
vector<int> adj[NN];
int nn = 0;
map<pii, int> mp;
void bfs(){
	while(!que.empty()){
		int u = que.front();
		vst[u] = 1;
		que.pop();
		for(int i = 0; i < adj[u].size(); i++){
			int v = adj[u][i];
			if(vst[v]) continue;
			mp[pii(u, v)] = mp[pii(v, u)] = nn++;
			que.push(v);
		}
	}
}

int uu[NN], vv[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n - 1; i++){
		scanf("%d%d", &uu[i], &vv[i]);
		adj[uu[i]].push_back(vv[i]);
		adj[vv[i]].push_back(uu[i]);
	}

	for(int i = 1; i <= n; i++) {
		if(adj[i].size() == 1) {
			que.push(i);
		}
	}

	bfs();

	for(int i = 1; i <= n - 1; i++){
		printf("%d\n", mp[pii(uu[i], vv[i])]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define x first
#define y second
using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
map<pii, int> mp;
set<int> num;
pii edge[NN];
int n;
int father[NN], vst[NN];
vector<int> adj[NN];
int a, b;

int dfs(int u, int pre=-1) {
	father[u]=pre;
	vst[u]=1;
	if (adj[u].size()==1 and adj[u][0]==pre) return u;
	for (auto v : adj[u]) {
		if (vst[v]) continue;
		return dfs(v, u);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=0; i<n-1; i++) num.insert(i);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i]=pii(u,v);
		adj[u].push_back(v), adj[v].push_back(u);
	}
	a=dfs(1), b=dfs(1);

	mp[pii(a, father[a])]=mp[pii(father[a], a)]=0;
	mp[pii(b, father[b])]=mp[pii(father[b], b)]=n-2;
	num.erase(0), num.erase(n-2);
	for (int i=father[a]; i!=1; i=father[i]) mp[pii(i, father[i])]=mp[pii(father[i], i)]=*num.begin(), num.erase(num.begin());
	for (int i=father[b]; i!=1; i=father[i]) mp[pii(i, father[i])]=mp[pii(father[i], i)]=*num.begin(), num.erase(num.begin());
	for (int i=1; i<n; i++) if (!mp.count(pii(edge[i].x, edge[i].y))) mp[pii(edge[i].x, edge[i].y)]=mp[pii(edge[i].y, edge[i].x)]=*num.begin(), num.erase(num.begin());

	for (int i=1; i<n; i++) printf("%d\n", mp[pii(edge[i].x, edge[i].y)]);
	return 0;
}


#include <bits/stdc++.h>

#define x first
#define y second
using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
map<pii, int> mp;
set<int> num;
pii edge[NN];
int n;
int father[NN], vst[NN];
vector<int> adj[NN];
int a, b;

int dfs(int u, int pre=-1) {
	father[u]=pre;
	vst[u]=1;
	if (adj[u].size()==1 and adj[u][0]==pre) return u;
	for (auto v : adj[u]) {
		if (vst[v]) continue;
		return dfs(v, u);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=0; i<n-1; i++) num.insert(i);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i]=pii(u,v);
		adj[u].push_back(v), adj[v].push_back(u);
	}
	a=dfs(1), b=dfs(1);

	mp[pii(a, father[a])]=mp[pii(father[a], a)]=0;
	mp[pii(b, father[b])]=mp[pii(father[b], b)]=n-2;
	num.erase(0), num.erase(n-2);
	for (int i=father[a]; i!=1; i=father[i]) mp[pii(min(i, father[i]), max(i, father[i]))]=*num.begin(), num.erase(num.begin());
	for (int i=father[b]; i!=1; i=father[i]) mp[pii(min(i, father[i]), max(i, father[i]))]=*num.begin(), num.erase(num.begin());

	for (int i=1; i<n; i++) printf("%d\n", mp[pii(min(edge[i].x, edge[i].y), max(edge[i].x, edge[i].y))]);
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
int power(int a, int b, int c=mod) {
    int ans=1;
    for(; b; b>>=1, a=(LL)a*a%c) {
        if(b&1) ans=(LL)ans*a%c;
    }
    return ans;
}
vector <int> adj[100100];
int fl[100100],u[100100],v[100100];
int main() {
#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
      scanf("%d%d",u+i,v+i);
      adj[u[i]].pb(v[i]);
      adj[v[i]].pb(u[i]);
    }
    int mx=0;
    for(int i=1;i<=n;i++) {
      int sz=adj[i].size();
      mx=max(mx,sz);
    }
    if(n==2) {cout<<0<<endl;return 0;}
    if(n==3) {cout<<0<<endl<<1<<endl;return 0;}
    if(mx==2){
      for(int i=0;i<n-1;i++) cout<<i<<endl;
      return 0;
    }
    int id=0;
    for(int i=1;i<=n;i++) {
      if(adj[i].size()==1) fl[i]=++id;
      if(id==3) break;
    }
    id=2;
    for(int i=1;i<n;i++){
      if(fl[u[i]] or fl[v[i]]) cout<<fl[u[i]]+fl[v[i]]-1<<endl;
      else cout<<++id<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define x first
#define y second
using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
map<pii, int> mp;
set<int> num;
pii edge[NN];
int n;
int father[NN], vst[NN];
vector<int> adj[NN];
int a, b;

int dfs(int u, int pre=-1) {
	father[u]=pre;
	vst[u]=1;
	if (adj[u].size()==1 and adj[u][0]==pre) return u;
	for (auto v : adj[u]) {
		if (vst[v]) continue;
		return dfs(v, u);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=0; i<n-1; i++) num.insert(i);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i]=pii(u,v);
		adj[u].push_back(v), adj[v].push_back(u);
	}
	a=dfs(1), b=dfs(1);

	mp[pii(a, father[a])]=mp[pii(father[a], a)]=0;
	mp[pii(b, father[b])]=mp[pii(father[b], b)]=n-2;
	num.erase(0), num.erase(n-2);
	for (int i=father[a]; i!=1; i=father[i]) mp[pii(min(i, father[i]), max(i, father[i]))]=*num.begin(), num.erase(num.begin());
	for (int i=father[b]; i!=1; i=father[i]) mp[pii(min(i, father[i]), max(i, father[i]))]=*num.begin(), num.erase(num.begin());
	for (int i=1; i<n; i++) {
		if (mp.count(pii(min(edge[i].x, edge[i].y), max(edge[i].y, edge[i].x))))
			printf("%d\n", mp[pii(min(edge[i].x, edge[i].y), max(edge[i].y, edge[i].x))]);
		else {printf("%d\n", *num.begin()); num.erase(num.begin());}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
int n;
map<pii, int> mp;
int ans[NN];
vector<int> adj[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=1; i<n; i++) {
		int u,v;
		scanf("%d%d", &u, &v);
		mp[pii(u,v)]=mp[pii(v,u)]=i;
		adj[u].push_back(v), adj[v].push_back(u);
	}
	int num=0;
	memset (ans, -1, sizeof (ans));
	int vtx=-1;
	for (int i=1; i<=n; i++) {
		if (adj[i].size()>2) {vtx=i; break;}
	}
	if (vtx!=-1)
		for (auto v : adj[vtx]) {
			ans[mp[pii(v, vtx)]]=num++;
			if (num>=3) break;
		}
	for (int i=1; i<n; i++) {
		cout<<(ans[i]!=-1 ? ans[i] : num++) <<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

#define NN 100100

using namespace std;

typedef long long INT;
typedef pair<int,int>pii;

int co[NN];
vector<int>adj[NN];
map<pii,int>mp;

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
		mp[pii(u,v)]=i;
		mp[pii(v,u)]=i;
	}
	int flag=0;
	for(int i=1;i<=n;i++){
		if(adj[i].size()>2){
			flag=i;
			break;
		}
	}
	if(!flag){
		for(int i=0;i<n-1;i++)printf("%d\n",i);
		return 0;
	}

	int ok=1;
	for(int v:adj[flag]){
		co[mp[pii(v,flag)]]=ok++;
		if(ok>3)break;
	}
	for(int i=1;i<n;i++){
		if(!co[i])co[i]=ok++;
	}
	for(int i=1;i<n;i++)printf("%d\n",co[i]-1);

	return 0;
}


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

typedef long long INT;
typedef pair<int, int> pii;

queue <int> que;
bool vst[NN];
vector<int> adj[NN];
int nn = 0;
map<pii, int> mp;
void bfs(){
	while(!que.empty()){
		int u = que.front();
		vst[u] = 1;
		que.pop();
		for(int i = 0; i < adj[u].size(); i++){
			int v = adj[u][i];
			if(vst[v]) continue;
			mp[pii(u, v)] = mp[pii(v, u)] = nn++;
			que.push(v);
		}
	}
}

int uu[NN], vv[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n - 1; i++){
		scanf("%d%d", &uu[i], &vv[i]);
		adj[uu[i]].push_back(vv[i]);
		adj[vv[i]].push_back(uu[i]);
	}

	for(int i = 1; i <= n; i++) {
		if(adj[i].size() == 1) {
			que.push(i);
			vst[i] = 1;
		}
	}

	bfs();

	for(int i = 1; i <= n - 1; i++){
		printf("%d\n", max(mp[pii(uu[i], vv[i])], mp[pii(vv[i], uu[i])]));
	}

	return 0;
}


#include <bits/stdc++.h>

#define x first
#define y second
using namespace std;

#define NN 100010
using INT = long long;
using pii = pair<int, int>;
map<pii, int> mp;
set<int> num;
pii edge[NN];
int n;
int father[NN], vst[NN];
vector<int> adj[NN];
int a, b;

int dfs(int u, int pre=-1) {
	father[u]=pre;
	vst[u]=1;
	if (adj[u].size()==1 and adj[u][0]==pre) return u;
	for (auto v : adj[u]) {
		if (vst[v]) continue;
		return dfs(v, u);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=0; i<n-1; i++) num.insert(i);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i]=pii(u,v);
		adj[u].push_back(v), adj[v].push_back(u);
	}
	a=dfs(1), b=dfs(1);

	mp[pii(a, father[a])]=mp[pii(father[a], a)]=0;
	mp[pii(b, father[b])]=mp[pii(father[b], b)]=n-2;
	num.erase(0), num.erase(n-2);
	for (int i=father[a]; i!=1; i=father[i]) mp[pii(i, father[i])]=mp[pii(father[i], i)]=*num.begin(), num.erase(num.begin());
	for (int i=father[b]; i!=1; i=father[i]) mp[pii(i, father[i])]=mp[pii(father[i], i)]=*num.begin(), num.erase(num.begin());
	for (int i=1; i<n; i++) if (!mp.count(pii(edge[i].x, edge[i].y))) mp[pii(edge[i].x, edge[i].y)]=mp[pii(edge[i].y, edge[i].x)]=*num.begin(), num.erase(num.begin());

	for (int i=1; i<n; i++) cout<<mp[pii(edge[i].x, edge[i].y)]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void topo(vector<vector<int> > &v, unordered_map<pair<int, int> > &mp, int node, int parent, int &label) {
    for (int i = 0; i < v[node].size(); i++) {
        if (v[node][i] != parent) {
            topo(v, mp, v[node][i], node, label);
        }
    }
    mp[{parent, node}] = label;
    mp[{node, parent}] = label;
    label++;
}
int main() {
    int n;
    cin >> n;
    if (n == 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<vector<int> > v(n);
    unordered_map<pair<int, int> > mp;
    vector<pair<int, int> > save;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
        save.push_back({x-1, y-1});
    }
    int label = 0;
    for (int i = 0; i < n; i++) {
        if (v[i].size() > 1) {
            topo(v, mp, i, i, label);
            break;
        }
    }
    for (int i = 0; i < save.size(); i++) {
        cout << mp[save[i]] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// void topo(vector<vector<int> > &v, map<pair<int, int>, int> &mp, int node, int parent, int &label) {
//     for (int i = 0; i < v[node].size(); i++) {
//         if (v[node][i] != parent) {
//             topo(v, mp, v[node][i], node, label);
//         }
//     }
//     if (node == parent) {
//         return;
//     }
//     mp[{parent, node}] = label;
//     mp[{node, parent}] = label;
//     label++;
// }
int main() {
    int n;
    cin >> n;
    if (n == 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<vector<int> > v(n);
    map<pair<int, int>, int> mp;
    vector<pair<int, int> > save;
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
        save.push_back({x-1, y-1});
    }
    int label = 0;
    for (int i = 0; i < n; i++) {
        if (v[i].size() == 1) {
            mp[{i, v[i][0]}] = label;
            mp[{v[i][0], i}] = label++;
        }
    }
    for (int i = 0; i < save.size(); i++) {
        if (mp.find(save[i]) != mp.end()) {
            cout << mp[save[i]] << endl;
        } else {
            cout << label++ << endl;
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e9+50||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+10000; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
//	 	printf("%.15lf %.15lf %.15lf\n",l,r,mid);
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
//	 printf("%.15lf\n",p);
	 if(p==0) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>1e9||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<bits/stdc++.h>
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=2020;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
int a[N],b[N];
int n;
double m;
bool check(double res){
    double sum=res+m;
    for(int i=0;i<n-1;i++){
        sum-=(sum/a[i]);
        sum-=(sum/b[i+1]);
    }
    sum-=(sum/a[n-1]);
    sum-=(sum/b[0]);
    return sum>=m;
}
void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    double l=0,r=1000000000;
    double eps=2e-7;
    while(l+eps<r){
        double mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    double res=l;
    for(int i=0;i<n-1;i++){
        res-=(res/a[i]);
        res-=(res/b[i+1]);
    }
    res-=(res/a[n-1]);
    res-=(res/b[0]);
    if(res>0) printf("%.10f\n",l);
    else printf("-1\n");
}
int main(){
    //IOS;
    solve();
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 float  r=1e9; float l=k;
	 while(l+1e-6<=r)
	 {
	 	 float mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if((p)>1e9+1||(p)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	printf("%.15lf\n",x);
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	printf("%.15lf\n",x);
//	if(x>=k) printf("1\n");
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+1; double l=k-1;
	 while(l+1e-6<=r)
	 {
	 	 double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
//		   printf("   %.15lf\n",p);
		}
		else
		{
		   l=mid;
		}
	 }
	if(p>1e9+0.5||p<k-0.5) printf("-1\n");
	else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>1e9+100||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	printf("%.15lf\n",x);
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	printf("%.15lf\n",x);
//	if(x>=k) printf("1\n");
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+1; double l=k-1;
	 while(l+2e-7<=r)
	 {
	 	 double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
//		   printf("   %.15lf\n",p);
		}
		else
		{
		   l=mid;
		}
	 }
	if(p>1e9+0.5||p<k-0.5) printf("-1\n");
	else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   p=mid;
		}
		else
		{
		   l=mid;
		   p=mid;
		}
	 }
	 ;
	 if(p>1e9+100||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if((p-k)>1e9||(p-k)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	 double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(check(p)==0) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if((p-k)<0) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-7<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>1e9+100||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+10000; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if((p-k)<0) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(p>=1e9) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(p>=1e9||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-7<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e9+1||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>1e9+100||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+2; double l=k;
	 while(l+1e-6<=r)
	 {
	 	 double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if((p)>1e9+1||(p)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e9+1||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if((p)>1e9||(p)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		}
		else
		{
		   l=mid;
		   p=mid;
		}
	 }
	 ;
	 if(p>1e9+100||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e13+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e13+1||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	  if(p==1e9)
	  {
	  	printf("%.6lf\n",p);
	  }
	  else
	  {
	 if((p)>1e9+1||(p)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);
      }

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(p<k-1) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	printf("%.15lf\n",x);
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	printf("%.15lf\n",x);
//	if(x>=k) printf("1\n");
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     float p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+1; double l=k-1;
	 while(l+1e-6<=r)
	 {
	 	 double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
//		   printf("   %.15lf\n",p);
		}
		else
		{
		   l=mid;
		}
	 }
	if(p>1e9+0.5||p<k-0.5) printf("-1\n");
	else printf("%.6lf\n",p);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9; double l=k;
	 while(l+1e-6<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
		   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if((p)>1e9+1||(p)<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-8<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(p>=1e9) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e9+100; double l=k;
	 while(l+1e-7<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 if(p>=1e9||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e17+100; double l=k;
	 while(l+1e-7<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e17+1||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm],num[mm];
ll n,k;
bool check(double x)
{
	if(x<=k)return 0;
//	cout<<x<<' ';
	x=x-x/1.0/d[1];
	for(ll i=2;i<=n;i++)
	{
		x=x-x/1.0/num[i];
		x=x-x/1.0/d[i];
	}
	x=x-x/1.0/num[1];
//	cout<<x<<endl;
	if(x>=k) return 1;
	else return 0;
}
int main()
{
     ll m,i,j,t,a,b,c,kk;
     double p=0;
	 scanf("%lld",&n);
	 scanf("%lld",&k);
	 for(i=1;i<=n;i++) scanf("%lld",&d[i]);
	 for(i=1;i<=n;i++) scanf("%lld",&num[i]);
	 double  r=1e10+100; double l=k;
	 while(l+1e-7<=r)
	 {
	 	double mid=(l+r)/2.0;
	 	if(check(mid))
	 	{
	 	   r=mid;
		   p=mid;
		}
		else
		{
		   l=mid;
		}
	 }
	 ;
	 if(p>=1e10+1||p<k) printf("-1\n");
	 else printf("%.6lf\n",p-k);

}


//I_l_M_P
#include <bits/stdc++.h>

#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
  char *res = allocator_memory + allocator_pos;
  allocator_pos += n;
  assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
  return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

template <class T = int> inline T readInt();
inline double readDouble();
inline int readUInt();
inline int readChar();
inline void readWord(char *s);
inline bool readLine(char *s);
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
  ~buffer_flusher_t() {
    flush();
  }
} buffer_flusher;

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
  if (buf_pos == buf_len) {
    buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
    if (buf_pos == buf_len)
      return 1;
  }
  return 0;
}

inline int getChar() {
  return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
  return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
  int c;
  while ((c = peekChar()) != -1 && c <= 32)
    buf_pos++;
  return c == -1;
}

inline void skipBlanks() {
  while (!isEof() && buf[buf_pos] <= 32U)
    buf_pos++;
}

inline int readChar() {
  int c = getChar();
  while (c != -1 && c <= 32)
    c = getChar();
  return c;
}

inline int readUInt() {
  int c = readChar(), x = 0;
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return x;
}

template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-')
    s = -1, c = getChar();
  else if (c == '+')
    c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}

inline double readDouble() {
  int s = 1, c = readChar();
  double x = 0;
  if (c == '-')
    s = -1, c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  if (c == '.') {
    c = getChar();
    double coef = 1;
    while ('0' <= c && c <= '9')
      x += (c - '0') * (coef *= 1e-1), c = getChar();
  }
  return s == 1 ? x : -x;
}

inline void readWord(char *s) {
  int c = readChar();
  while (c > 32)
    *s++ = c, c = getChar();
  *s = 0;
}

inline bool readLine(char *s) {
  int c = getChar();
  while (c != '\n' && c != -1)
    *s++ = c, c = getChar();
  *s = 0;
  return c != -1;
}

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
  if (write_buf_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
  write_buf[write_buf_pos++] = x;
}

inline void flush() {
  if (write_buf_pos) {
    fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
    fflush(stdout);
  }
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n < output_len)
    s[n++] = '0';
  while (n--)
    writeChar(s[n]);
  if (end)
    writeChar(end);
}

inline void writeWord(const char *s) {
  while (*s)
    writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  int t = (int)x;
  writeInt(t), x -= t;
  writeChar('.');
  for (int i = output_len - 1; i > 0; i--) {
    x *= 10;
    t = std::min(9, (int)x);
    writeChar('0' + t), x -= t;
  }
  x *= 10;
  t = std::min(9, (int)(x + 0.5));
  writeChar('0' + t);
}

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

typedef long double ld;
typedef long long ll;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define int ll

#define right rightt
#define left leftt
#define prev prevv
#define next nextt

mt19937 Random(time(0));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const ld EPS = 1e-9;

void source() {
  int n = readInt(), m = readInt();
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = readInt();
  }
  for (int i = 0; i < n; i++) {
    b[i] = readInt();
  }
  ld l = 0, r = INF;
  for (int iter = 0; iter < 500; iter++) {
    ld mid = (l + r) / 2.0, cur = mid + m;
    bool t = true;
    for (int i = 0; i < n; i++) {
      cur -= cur / (ld)a[i];
      if (abs((ld)m - cur) > EPS) {
        t = false;
        break;
      }
      cur -= cur / (ld)b[(i + 1) % n];
      if (abs((ld)m - cur) > EPS) {
        t = false;
        break;
      }
    }
    if (t) {
      r = mid;
    }
    else {
      l = mid;
    }
  }
  if (r > 1e9) {
    writeInt(-1);
  }
  else {
    writeDouble(r, 10);
  }
}

signed main() {
#ifdef extraterrestrial_
  assert(freopen("input.txt", "r", stdin));
  //assert(freopen("output.txt", "w", stdout));
#else
  #define TASK ""
  //assert(freopen(TASK".in", "r", stdin));
  //assert(freopen(TASK".out", "w", stdout));
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
#ifdef extraterrestrial_
  writeWord("\n\t");
  writeDouble((double)clock() / (double)CLOCKS_PER_SEC, 10);
  writeWord(" seconds\n\n");
#endif
  return 0;
}


//I_l_M_P
#include <bits/stdc++.h>

#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
  char *res = allocator_memory + allocator_pos;
  allocator_pos += n;
  assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
  return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

template <class T = int> inline T readInt();
inline double readDouble();
inline int readUInt();
inline int readChar();
inline void readWord(char *s);
inline bool readLine(char *s);
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
  ~buffer_flusher_t() {
    flush();
  }
} buffer_flusher;

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
  if (buf_pos == buf_len) {
    buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
    if (buf_pos == buf_len)
      return 1;
  }
  return 0;
}

inline int getChar() {
  return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
  return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
  int c;
  while ((c = peekChar()) != -1 && c <= 32)
    buf_pos++;
  return c == -1;
}

inline void skipBlanks() {
  while (!isEof() && buf[buf_pos] <= 32U)
    buf_pos++;
}

inline int readChar() {
  int c = getChar();
  while (c != -1 && c <= 32)
    c = getChar();
  return c;
}

inline int readUInt() {
  int c = readChar(), x = 0;
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return x;
}

template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-')
    s = -1, c = getChar();
  else if (c == '+')
    c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}

inline double readDouble() {
  int s = 1, c = readChar();
  double x = 0;
  if (c == '-')
    s = -1, c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  if (c == '.') {
    c = getChar();
    double coef = 1;
    while ('0' <= c && c <= '9')
      x += (c - '0') * (coef *= 1e-1), c = getChar();
  }
  return s == 1 ? x : -x;
}

inline void readWord(char *s) {
  int c = readChar();
  while (c > 32)
    *s++ = c, c = getChar();
  *s = 0;
}

inline bool readLine(char *s) {
  int c = getChar();
  while (c != '\n' && c != -1)
    *s++ = c, c = getChar();
  *s = 0;
  return c != -1;
}

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
  if (write_buf_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
  write_buf[write_buf_pos++] = x;
}

inline void flush() {
  if (write_buf_pos) {
    fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
    fflush(stdout);
  }
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n < output_len)
    s[n++] = '0';
  while (n--)
    writeChar(s[n]);
  if (end)
    writeChar(end);
}

inline void writeWord(const char *s) {
  while (*s)
    writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  int t = (int)x;
  writeInt(t), x -= t;
  writeChar('.');
  for (int i = output_len - 1; i > 0; i--) {
    x *= 10;
    t = std::min(9, (int)x);
    writeChar('0' + t), x -= t;
  }
  x *= 10;
  t = std::min(9, (int)(x + 0.5));
  writeChar('0' + t);
}

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

typedef long double ld;
typedef long long ll;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
//#define int ll

#define right rightt
#define left leftt
#define prev prevv
#define next nextt

mt19937 Random(time(0));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;

void source() {
  int n = readInt(), m = readInt();
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = readInt();
  }
  for (int i = 0; i < n; i++) {
    b[i] = readInt();
  }
  ld l = 0, r = INF;
  for (int iter = 0; iter < 300; iter++) {
    ld mid = (l + r) / 2.0, cur = mid + m;
    bool t = true;
    for (int i = 0; i < n; i++) {
      cur -= cur / (ld)a[i];
      if (cur < m) {
        t = false;
        break;
      }
      cur -= cur / (ld)b[(i + 1) % n];
      if (cur < m) {
        t = false;
        break;
      }
    }
    if (t) {
      r = mid;
    }
    else {
      l = mid;
    }
  }
  if (r > 1e9) {
    writeInt(-1);
  }
  else {
    writeDouble(r, 10);
  }
}

signed main() {
#ifdef extraterrestrial_
  assert(freopen("input.txt", "r", stdin));
  //assert(freopen("output.txt", "w", stdout));
#else
  #define TASK ""
  //assert(freopen(TASK".in", "r", stdin));
  //assert(freopen(TASK".out", "w", stdout));
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
#ifdef extraterrestrial_
  writeWord("\n\t");
  writeDouble((double)clock() / (double)CLOCKS_PER_SEC, 10);
  writeWord(" seconds\n\n");
#endif
  return 0;
}


//I_l_M_P
#include <bits/stdc++.h>

#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
  char *res = allocator_memory + allocator_pos;
  allocator_pos += n;
  assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
  return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

template <class T = int> inline T readInt();
inline double readDouble();
inline int readUInt();
inline int readChar();
inline void readWord(char *s);
inline bool readLine(char *s);
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
  ~buffer_flusher_t() {
    flush();
  }
} buffer_flusher;

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
  if (buf_pos == buf_len) {
    buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
    if (buf_pos == buf_len)
      return 1;
  }
  return 0;
}

inline int getChar() {
  return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
  return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
  int c;
  while ((c = peekChar()) != -1 && c <= 32)
    buf_pos++;
  return c == -1;
}

inline void skipBlanks() {
  while (!isEof() && buf[buf_pos] <= 32U)
    buf_pos++;
}

inline int readChar() {
  int c = getChar();
  while (c != -1 && c <= 32)
    c = getChar();
  return c;
}

inline int readUInt() {
  int c = readChar(), x = 0;
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return x;
}

template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-')
    s = -1, c = getChar();
  else if (c == '+')
    c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}

inline double readDouble() {
  int s = 1, c = readChar();
  double x = 0;
  if (c == '-')
    s = -1, c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  if (c == '.') {
    c = getChar();
    double coef = 1;
    while ('0' <= c && c <= '9')
      x += (c - '0') * (coef *= 1e-1), c = getChar();
  }
  return s == 1 ? x : -x;
}

inline void readWord(char *s) {
  int c = readChar();
  while (c > 32)
    *s++ = c, c = getChar();
  *s = 0;
}

inline bool readLine(char *s) {
  int c = getChar();
  while (c != '\n' && c != -1)
    *s++ = c, c = getChar();
  *s = 0;
  return c != -1;
}

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
  if (write_buf_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
  write_buf[write_buf_pos++] = x;
}

inline void flush() {
  if (write_buf_pos) {
    fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
    fflush(stdout);
  }
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n < output_len)
    s[n++] = '0';
  while (n--)
    writeChar(s[n]);
  if (end)
    writeChar(end);
}

inline void writeWord(const char *s) {
  while (*s)
    writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  int t = (int)x;
  writeInt(t), x -= t;
  writeChar('.');
  for (int i = output_len - 1; i > 0; i--) {
    x *= 10;
    t = std::min(9, (int)x);
    writeChar('0' + t), x -= t;
  }
  x *= 10;
  t = std::min(9, (int)(x + 0.5));
  writeChar('0' + t);
}

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

typedef long double ld;
typedef long long ll;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define int ll

#define right rightt
#define left leftt
#define prev prevv
#define next nextt

mt19937 Random(time(0));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const ld EPS = 1e-9;

void source() {
  int n = readInt(), m = readInt();
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = readInt();
  }
  for (int i = 0; i < n; i++) {
    b[i] = readInt();
  }
  ld l = 0, r = INF;
  for (int iter = 0; iter < 500; iter++) {
    ld mid = (l + r) / 2.0, cur = mid + m;
    bool t = true;
    for (int i = 0; i < n; i++) {
      cur -= cur / (ld)a[i];
      if ((ld)m - cur > EPS) {
        t = false;
        break;
      }
      cur -= cur / (ld)b[(i + 1) % n];
      if ((ld)m - cur > EPS) {
        t = false;
        break;
      }
    }
    if (t) {
      r = mid;
    }
    else {
      l = mid;
    }
  }
  if (r > 1e9) {
    writeInt(-1);
  }
  else {
    writeDouble(r, 10);
  }
}

signed main() {
#ifdef extraterrestrial_
  assert(freopen("input.txt", "r", stdin));
  //assert(freopen("output.txt", "w", stdout));
#else
  #define TASK ""
  //assert(freopen(TASK".in", "r", stdin));
  //assert(freopen(TASK".out", "w", stdout));
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
#ifdef extraterrestrial_
  writeWord("\n\t");
  writeDouble((double)clock() / (double)CLOCKS_PER_SEC, 10);
  writeWord(" seconds\n\n");
#endif
  return 0;
}


//I_l_M_P
#include <bits/stdc++.h>

#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
  char *res = allocator_memory + allocator_pos;
  allocator_pos += n;
  assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
  return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

template <class T = int> inline T readInt();
inline double readDouble();
inline int readUInt();
inline int readChar();
inline void readWord(char *s);
inline bool readLine(char *s);
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
  ~buffer_flusher_t() {
    flush();
  }
} buffer_flusher;

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
  if (buf_pos == buf_len) {
    buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
    if (buf_pos == buf_len)
      return 1;
  }
  return 0;
}

inline int getChar() {
  return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
  return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
  int c;
  while ((c = peekChar()) != -1 && c <= 32)
    buf_pos++;
  return c == -1;
}

inline void skipBlanks() {
  while (!isEof() && buf[buf_pos] <= 32U)
    buf_pos++;
}

inline int readChar() {
  int c = getChar();
  while (c != -1 && c <= 32)
    c = getChar();
  return c;
}

inline int readUInt() {
  int c = readChar(), x = 0;
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return x;
}

template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-')
    s = -1, c = getChar();
  else if (c == '+')
    c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}

inline double readDouble() {
  int s = 1, c = readChar();
  double x = 0;
  if (c == '-')
    s = -1, c = getChar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = getChar();
  if (c == '.') {
    c = getChar();
    double coef = 1;
    while ('0' <= c && c <= '9')
      x += (c - '0') * (coef *= 1e-1), c = getChar();
  }
  return s == 1 ? x : -x;
}

inline void readWord(char *s) {
  int c = readChar();
  while (c > 32)
    *s++ = c, c = getChar();
  *s = 0;
}

inline bool readLine(char *s) {
  int c = getChar();
  while (c != '\n' && c != -1)
    *s++ = c, c = getChar();
  *s = 0;
  return c != -1;
}

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
  if (write_buf_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
  write_buf[write_buf_pos++] = x;
}

inline void flush() {
  if (write_buf_pos) {
    fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
    fflush(stdout);
  }
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n < output_len)
    s[n++] = '0';
  while (n--)
    writeChar(s[n]);
  if (end)
    writeChar(end);
}

inline void writeWord(const char *s) {
  while (*s)
    writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
  if (x < 0)
    writeChar('-'), x = -x;
  int t = (int)x;
  writeInt(t), x -= t;
  writeChar('.');
  for (int i = output_len - 1; i > 0; i--) {
    x *= 10;
    t = std::min(9, (int)x);
    writeChar('0' + t), x -= t;
  }
  x *= 10;
  t = std::min(9, (int)(x + 0.5));
  writeChar('0' + t);
}

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

typedef long double ld;
typedef long long ll;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define int ll

#define right rightt
#define left leftt
#define prev prevv
#define next nextt

mt19937 Random(time(0));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;

void source() {
  int n = readInt(), m = readInt();
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = readInt();
  }
  for (int i = 0; i < n; i++) {
    b[i] = readInt();
  }
  ld l = 0, r = INF;
  for (int iter = 0; iter < 500; iter++) {
    ld mid = (l + r) / 2.0, cur = mid + m;
    bool t = true;
    for (int i = 0; i < n; i++) {
      cur -= cur / (ld)a[i];
      if (cur < m) {
        t = false;
        break;
      }
      cur -= cur / (ld)b[(i + 1) % n];
      if (cur < m) {
        t = false;
        break;
      }
    }
    if (t) {
      r = mid;
    }
    else {
      l = mid;
    }
  }
  if (r > 1e9) {
    writeInt(-1);
  }
  else {
    writeDouble(r, 10);
  }
}

signed main() {
#ifdef extraterrestrial_
  assert(freopen("input.txt", "r", stdin));
  //assert(freopen("output.txt", "w", stdout));
#else
  #define TASK ""
  //assert(freopen(TASK".in", "r", stdin));
  //assert(freopen(TASK".out", "w", stdout));
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
#ifdef extraterrestrial_
  writeWord("\n\t");
  writeDouble((double)clock() / (double)CLOCKS_PER_SEC, 10);
  writeWord(" seconds\n\n");
#endif
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 1000000007
#define v1d vector<int>
#define v2d vector<vector<int>>
#define v1s vector<string>
#define v2s vector<vector<string> >
#define v1l vector<double>
#define v2l vector<vector<double> >

bool check(v1d &a,v1d &b,double p,int n,int m){
    double x= (m+p)/(1.0*a[0]);
    p-=x;
    for(int i=1;i<=n-1&&p>0;i++){
        x= (m+p)/(1.0*b[i]);
        p-=x;
        x= (m+p)/(1.0*a[i]);
        p-=x;
        if(p<0)return false;
    }
    x= (m+p)/(1.0*b[0]);
    p-=x;
    if(p<0){
        return false;
    }
    return true;
}

int32_t main(){
    IOS;
    cout.precision(6);
    int n,m;cin>>n>>m;
    v1d a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    int p= 1000000000;
    /*if(check(a,b,85.47,n,m)){
        cout<<"haha";
    }
    if(check(a,b,85.48,n,m)){
        cout<<"ha";
    }*/
    int s=0,e=p;
    while(s<=e){
        int mid=(s+e)/2;
        if(check(a,b,mid,n,m)){
            p=min(p,mid);
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
    if(p>=1000000000){
        cout<<-1;return 0;
    }
    bool flag=false;
    double res=p-1;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                for(int x=0;x<=9;x++){
                double q=res+ (i*1000.0+j*100.0+k*10.0+x*1.0)/10000.0;
                if(check(a,b,q,n,m)){
                    cout<<q;return 0;
                }
                }
            }
        }
    }
    cout<<p;

    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 1000000007
#define v1d vector<int>
#define v2d vector<vector<int>>
#define v1s vector<string>
#define v2s vector<vector<string> >
#define v1l vector<double>
#define v2l vector<vector<double> >

bool check(v1d &a,v1d &b,double p,int n,int m){
    double x= (m+p)/(1.0*a[0]);
    p-=x;
    for(int i=1;i<=n-1&&p>0;i++){
        x= (m+p)/(1.0*b[i]);
        p-=x;
        x= (m+p)/(1.0*a[i]);
        p-=x;
        if(p<0)return false;
    }
    x= (m+p)/(1.0*b[0]);
    p-=x;
    if(p<0){
        return false;
    }
    return true;
}

int32_t main(){
    IOS;
    cout.precision(12);
    int n,m;cin>>n>>m;
    v1d a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    int p= 1000000000;
    /*if(check(a,b,85.47,n,m)){
        cout<<"haha";
    }
    if(check(a,b,85.48,n,m)){
        cout<<"ha";
    }*/
    int s=0,e=p;
    while(s<=e){
        int mid=(s+e)/2;
        if(check(a,b,mid,n,m)){
            p=min(p,mid);
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
    if(p>=1000000000){
        cout<<-1;return 0;
    }
    bool flag=false;
    double res=p-1;
    double f=0.99999999999;
    double x=0.0,y=f;
    double fans=p;
    int i=0;
    while(i<1000){i++;
        double mid= (x+y)/2.0;//cout<<x<<" "<<y<<" "<<mid<<" "<<fans<<endl;
        if(check(a,b,res+mid,n,m)){
            if(fans>res+mid){
                fans=res+mid;flag=true;
            }
            y=mid;
        }
        else{
            x=mid;
        }
        if(x==y||x>y+0.000001){
            break;
        }
    }
    cout<<fixed<<fans;

    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 1000000007
#define v1d vector<int>
#define v2d vector<vector<int>>
#define v1s vector<string>
#define v2s vector<vector<string> >
#define v1l vector<double>
#define v2l vector<vector<double> >

bool check(v1d &a,v1d &b,double p,int n,int m){
    double x= (m+p)/(1.0*a[0]);
    p-=x;
    for(int i=1;i<=n-1&&p>0;i++){
        x= (m+p)/(1.0*b[i]);
        p-=x;
        x= (m+p)/(1.0*a[i]);
        p-=x;
        if(p<0)return false;
    }
    x= (m+p)/(1.0*b[0]);
    p-=x;
    if(p<0){
        return false;
    }
    return true;
}

int32_t main(){
    IOS;
    cout.precision(12);
    int n,m;cin>>n>>m;
    v1d a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    int p= 1000000005;
    /*if(check(a,b,85.47,n,m)){
        cout<<"haha";
    }
    if(check(a,b,85.48,n,m)){
        cout<<"ha";
    }*/
    int s=0,e=p;
    while(s<=e){
        int mid=(s+e)/2;
        if(check(a,b,mid,n,m)){
            p=min(p,mid);
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
    if(p>1000000000){
        cout<<-1;return 0;
    }
    bool flag=false;
    double res=p-1;
    double f=0.99999999999;
    double x=0.0,y=f;
    double fans=p;
    int i=0;
    while(i<1000){i++;
        double mid= (x+y)/2.0;//cout<<x<<" "<<y<<" "<<mid<<" "<<fans<<endl;
        if(check(a,b,res+mid,n,m)){
            if(fans>res+mid){
                fans=res+mid;flag=true;
            }
            y=mid;
        }
        else{
            x=mid;
        }
        if(x==y||x>y+0.000001){
            break;
        }
    }
    cout<<fixed<<fans;

    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 1000000007
#define v1d vector<int>
#define v2d vector<vector<int>>
#define v1s vector<string>
#define v2s vector<vector<string> >
#define v1l vector<double>
#define v2l vector<vector<double> >

bool check(v1d &a,v1d &b,double p,int n,int m){
    double x= (m+p)/(1.0*a[0]);
    p-=x;
    for(int i=1;i<=n-1&&p>0;i++){
        x= (m+p)/(1.0*b[i]);
        p-=x;
        x= (m+p)/(1.0*a[i]);
        p-=x;
        if(p<0)return false;
    }
    x= (m+p)/(1.0*b[0]);
    p-=x;
    if(p<0){
        return false;
    }
    return true;
}

int32_t main(){
    IOS;
    cout.precision(12);
    int n,m;cin>>n>>m;
    v1d a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    int p= 10000000000000;
    /*if(check(a,b,85.47,n,m)){
        cout<<"haha";
    }
    if(check(a,b,85.48,n,m)){
        cout<<"ha";
    }*/
    int s=0,e=p;
    while(s<=e){
        int mid=(s+e)/2;
        if(check(a,b,mid,n,m)){
            p=min(p,mid);
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
    if(p>10000000000){
        cout<<-1;return 0;
    }
    bool flag=false;
    double res=p-1;
    double f=0.99999999999;
    double x=0.0,y=f;
    double fans=p;
    int i=0;
    while(i<1000){i++;
        double mid= (x+y)/2.0;//cout<<x<<" "<<y<<" "<<mid<<" "<<fans<<endl;
        if(check(a,b,res+mid,n,m)){
            if(fans>res+mid){
                fans=res+mid;flag=true;
            }
            y=mid;
        }
        else{
            x=mid;
        }
        if(x==y||x>y+0.000001){
            break;
        }
    }
    cout<<fixed<<fans;

    return 0;
}