/* #include void self::main(){ LL(N,M); VVL(N,M,a); fo(i,N)sort(a[i]); ll D=binary_search_first_true(-1,(int)oo,[&](ll D){ vec dp(N+1,M,i8{}); fo(j,M)dp[1][j]=1; fo(i,1,N){ SlideMaxs(dp[i],0,0); ll l=0,r=0; fo(j,M){ while(r0; }); pp(D==(int)oo?-1:D); } */ #include using namespace std; namespace self{void main();void sub();void pp(auto&&...a);void ppe(auto&&...a);} int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<>__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n,m);lin(__VA_ARGS__) #define VVL(n,m,...) RDVVL(ll,n,m,__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);iconstexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} templateconstexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} void lin(auto&...a){(cin>>...>>a);} constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;} templateconstexpr ll maxsize10(){return size10(numeric_limits::max());} ll binary_search_first_true(ll l,ll r,auto&&f){while(l+1struct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} auto operator<=>(const pair&)const=default; }; templatestruct infinity{ templatestatic constexpr T ones(size_t n){return n?ones(n-1)*10+1:0;} templateconstexpr operator T()const{return ones(maxsize10())*(1-is_negative*2);} }; constexpr infinity oo; template>decltype(auto)sort(auto&&a,F f={}){ranges::sort(a,f);return a;} templateusing pack_back_t=tuple_element_t>; } namespace self{ templateconcept vectorial=is_base_of_v::value_type>,remove_cvref_t>; templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateconstexpr int depth=0; templateconstexpr int depth =depth+1; templatestruct core_t_helper{using type=T;}; templatestruct core_t_helper{using type=typename core_t_helper::type;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);} void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else*this=make(a...);} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else return vec(n,make(a...)); } templatevoid for_each_core(F&&f)const{fe(*this,e){if constexpr(vectorial){ }else f(e);}} templateauto fold(auto&&f)const{ pairres{}; for_each_core([&](const C&e){ if(res.b)f(res.a,e); else res={e,1}; }); return res; } auto max()const{return fold([](auto&a,auto b){if(arequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; } namespace self{ templatestruct deque:std::deque{ deque()=default; ll size()const{return std::deque::size();} T pop_front(){T r=this->front();std::deque::pop_front();return r;} T pop_back(){T r=this->back();std::deque::pop_back();return r;} }; } namespace self{ templateclass SlideOpt{ public: dequeq_; vectora_; F comp_; int l_=0,r_=0; SlideOpt(const vec&a,int l,int r,F comp=F{}):a_(a),comp_(comp){ set_right(r); set_left(l); } ll size()const{return q_.size();} T top()const{return a_[q_.front()];} void set_left(int l){ assert(l_<=l&&l<=r_); while(q_.size()&&q_.front()using SlideMax=SlideOpt>; } void self::pp(auto&&...a){const char*c="";((cout<s(dp[i],0,0); ll l=0,r=0; fo(j,M){ while(r0; }); pp(D==(int)oo?-1:D); }