#include "bits/stdc++.h" // {{{ using namespace std; typedef long long ll; typedef pair pii; #define val const auto #define eb emplace_back #define emp emplace #define fi first #define se second #define outl(x) cout << (x) << '\n' #define reps(i,s,n) for(int i=(s); i < (int)(n); ++i) #define rep(i,n) reps(i,0,n) #define repr(i,h,l) for(int i=(h); i >= (int)(l); --i) #define ALL(x) begin(x), end(x) #define TMPLT(T,U) template #define ten(p) ((long long)(1e##p)) #define FILL(a,v) memset((a), (v), sizeof(a)) #ifdef DEBUG #define debug(...) fprintf(stderr, __VA_ARGS__) #define show(x) clog << #x << " \t\t= " << (x) << '\n' #define show2(x,y) clog << '(' << #x << ',' << #y << ")\t\t= " << '(' << (x) << "\t, " << (y) << ")\n" #define LN() fputs("\n--------------------------------\n", stderr) #else #define debug(...) #define show(x) #define show2(x,y) #define LN() #endif #define def(op) inline bool operator op (const T &that) const { return comp(that) op 0; } template struct Ordered { virtual int comp(const T &that) const = 0; def(==); def(!=); def(<); def(<=); def(>); def(>=); }; #undef def namespace { TMPLT(T,U) inline constexpr common_type_t gcd(T x, U y) { return (xa ? a=b,1 : 0;} TMPLT(T,U) inline bool chmin(T &a, const U &b){return b string mkString(Itr begin, Itr end, const char *sp = " ") { static ostringstream oss; oss.str(""); for(Itr i=begin; i != end; ++i) { if(i != begin)oss << sp; oss << *i; } return oss.str(); } constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; // }}} constexpr int MX = ten(5) + 10; struct Stack { int idx = 0; vector buf; Stack(): buf(MX) {} void push(int x){ buf[idx++] = x; } int pop() { return buf[--idx]; } int top() { return buf[idx-1]; } bool empty() { return idx <= 0; } }; void _main(const vector &args) { int N, M; static int r[MX][11]; static int cnt[MX] = {}; cin >> N >> M; reps(i, 1, N+1) rep(j, M) cin >> r[i][j]; Stack tops[11]; rep(i, M) { r[0][i] = -1; tops[i].push(0); } cnt[0] = M; int ans = 1; for (int i = 1; i <= N; ++i) { rep(j, M) { val R = r[i][j]; Stack &top = tops[j]; if (R > r[top.top()][j]) { while( !top.empty() ) { val idx = top.pop(); --cnt[idx]; if (cnt[idx] <= 0) { cnt[idx] = 0; --ans; } } top.push(i); ++cnt[i]; } else if (R == r[top.top()][j]) { top.push(i); ++cnt[i]; } } if (cnt[i] > 0) { ++ans; } outl(ans); } } } // {{{ signed main(signed argc, char *argv[]) { #ifndef DEBUG ios::sync_with_stdio(false); cin.tie(nullptr); #endif cout << fixed << setprecision(9); _main(vector(argv, argv+argc)); return 0; } // }}}