#include <cstdint>
#include <iostream>
#include <type_traits>
#include <vector>

using ll = int64_t;

ll t,ans{};
std::vector<ll> n,shans;
std::vector<std::vector<ll>> p;

template<class T>
ll getMaxAnd(T begin,T end){
    ll ans{};
    for(ll k=20;k>=0;k--){
        ll bit = ans|(1ll<<k);
        ll c{};
        for(std::decay_t<T> p=begin;p!=end;p++){
            if(((*p)&bit)==bit){
                c++;
            }
        }
        if(c>=2){
            ans=bit;
        }
    }
    return ans;
}

int main(){
    
    std::cin>>t;
    n.resize(t+1);
    p.resize(t+1);
    shans.resize(t+1);
    for(ll i=1;i<=t;i++){
        std::cin>>n[i];
        p[i].resize(n[i]+1);
        for(ll j=1;j<=n[i];j++){
            std::cin>>p[i][j];
        }
    }

    for(ll i=1;i<(ll)p.size();i++){
        shans[i]=getMaxAnd(p[i].begin()+1, p[i].end());
    }

    ans = getMaxAnd(shans.begin()+1, shans.end());

    std::cout<<ans<<'\n';
}