#include<bits/stdc++.h>
#define maxn 1005
#define ull unsigned __int128
using namespace std;
const int base=13;
int mul[1000005],a[maxn][1000],b[maxn][1000],length_[maxn],n;
ull pre[maxn][1000];
ull query(int id,int l,int r){return pre[id][r]-pre[id][l-1]*mul[r+1-l];}
map<ull,bool>vis[maxn];
bool check(int len){
for(int i=2;i<=n;++i)vis[i].clear();
for(int i=2;i<=n;++i)
for(int j=1;j+len-1<=length_[i];++j)
vis[i][query(i,j,j+len-1)]=1;
for(int i=1;i+len-1<=length_[1];++i){
ull noi=query(1,i,i+len-1);bool f=1;
for(int j=2;j<=n;++j){
if(!vis[j][noi]){
f=0;
break;
}
}
if(f)return 1;
}
return 0;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;mul[0]=1;int L=1,R=1e9,ans=-1;
for(int i=1;i<=n;++i){
cin>>length_[i];
for(int j=1;j<=length_[i];++j)cin>>b[i][j];
for(int j=length_[i]-1;j>=1;--j)a[i][j]=b[i][j+1]-b[i][j];length_[i]--;
for(int j=1;j<=length_[i];++j)pre[i][j]=(pre[i][j-1]*base+a[i][j]);
R=min(R,length_[i]);
}
for(int i=1;i<=1000000;++i)mul[i]=mul[i-1]*base;
while(L<=R){
int mid=L+R>>1;
if(check(mid))L=mid+1,ans=mid;
else R=mid-1;
}
cout<<ans+1;
return 0;
}