#include <cstdio>
using namespace std;
const int maxn = 1e3+5, maxm = 1e2+5;
int A[maxn][maxm],a[maxn][maxm],n[maxn];
int nxt[maxm];
int main() {
int N;
scanf("%d",&N);
for (int i = 1; i <= N; i++) {
scanf("%d",n+i);
for (int j = 0; j < n[i]; j++) {
scanf("%d",A[i]+j);
if (j > 0) a[i][j-1] = A[i][j]-A[i][j-1];
}
n[i]--;
}
nxt[1] = 0;
for (int i = 1; i < n[1]; i++) {
int j = nxt[i];
while(j && a[1][i]!=a[1][j]) j = nxt[j];
if (a[1][i] == a[1][j]) nxt[i+1] = j+1;
else nxt[i+1] = 0;
}
for (int len = n[1]; len >= 1; len--) {
bool F = 1;
for (int i = 2; i <= N; i++) {
if (n[i] < len) F = 0;
}
if (!F) continue;
F = 0;
for (int stt = 1; stt+len-1 <= n[1]; stt++) {
bool G = 1;
for (int I = 2; I <= N; I++) {
int cnt = 0;
for (int i = 0, j = 0; i <= n[I]; i++) {
while(j&&a[I][i]!=a[1][j+stt-1]) j = nxt[j];
if (a[I][i]==a[1][j+stt-1]) j++;
if (j == len) cnt++;
}
if (!cnt) {
G = 0; break;
}
}
if (G) {
F = 1; break;
}
}
if (F) {
printf("%d",len+1);
return 0;
}
}
}