#include<bits/stdc++.h> #define int long long #define ll long long usingnamespace std;
constint N = 1e6 + 66;
int n, k, col, cnt, l, r; int mp[66], res(12345678910);
structyhzhyhm { int id, val; booloperator < (const yhzhyhm &x) const {return id < x.id;} }yh[N], q[N];
signedmain() { int i, x, y; n = read(), k = read(); for (i = 1; i <= k; ++ i) { x = read(); while (x --) y = read(), yh[++ cnt].id = y, yh[cnt].val = i; } sort(yh + 1, yh + 1 + n);
for (i = 1; i <= n; ++ i) { q[++ r] = yh[i], ++ mp[yh[i].val]; if (mp[yh[i].val] == 1) ++ col; while (col == k) { res = min(res, q[r].id - q[l].id); -- mp[yh[l].val]; if (! mp[yh[l].val]) -- col; ++ l; } } put(res); return0; }