#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct Matrix{ typedef vector arr; typedef vector mat; mat dat; Matrix(size_t r,size_t c):dat(r,arr(c,K())){} Matrix(mat dat):dat(dat){} size_t size() const{return dat.size();}; bool empty() const{return size()==0;}; arr& operator[](size_t k){return dat[k];}; const arr& operator[](size_t k) const {return dat[k];}; static Matrix cross(const Matrix &A,const Matrix &B){ Matrix res(A.size(),B[0].size()); for(Int i=0;i<(Int)A.size();i++) for(Int j=0;j<(Int)B[0].size();j++) for(Int k=0;k<(Int)B.size();k++) res[i][j]+=A[i][k]*B[k][j]; return res; } static Matrix identity(size_t n){ Matrix res(n,n); for(Int i=0;i<(Int)n;i++) res[i][i]=K(1); return res; } Matrix pow(long long n) const{ Matrix a(dat),res=identity(size()); while(n){ if(n&1) res=cross(res,a); a=cross(a,a); n>>=1; } return res; } }; const Int INF = 1e15; struct R{ Int v; R():v(-INF){} R(Int x){if(x==1) v=0;} R operator+=(const R &a){ v=max(v,a.v); return *this; } R operator*=(const R &a){ v=v+a.v; return *this; } R operator+(const R &a) const{ R b(*this); return b+=a; } R operator*(const R &a) const{ R b(*this); return b*=a; } }; //INSERT ABOVE HERE signed main(){ using M = Matrix; Int n,m; cin>>n>>m; M A(m,m); for(Int i=0;i>A[i][j].v; M B(m,1); for(Int i=0;i