#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 5e5 + 10;
int a[maxn][10], back[maxn][10];
struct DSU {
  int pai[maxn], sz[maxn];
  DSU() {
    for (int i = 0; i < maxn; i++) pai[i] = i, sz[i] = 1;
  }
  int find(int x) { return pai[x] == x ? x : pai[x] = find(pai[x]); }
  bool join(int x, int y) {
    if (x != find(x)) puts("LIXO1");
    x = find(x), y = find(y);
    if (x == y) return 1;
    if (a[x][0] < a[y][0]) return 0;
    pai[y] = x;
    sz[x] += sz[y];
    return 1;
  }
} dsu;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) scanf("%d", &a[i][j]);
  }
  for (int j = 0; j < k; j++) {
    map<int, int> mp;
    for (int i = 0; i < n; i++) mp[a[i][j]];
    int aux = 0;
    for (auto& it : mp) it.second = ++aux;
    for (int i = 0; i < n; i++) a[i][j] = mp[a[i][j]], back[a[i][j]][j] = i;
  }
  set<int> st, ord[10];
  for (int i = 0; i < n; i++) {
    auto it = st.insert(a[i][0]).first;
    auto it2 = ord[0].insert(a[i][0]).first;
    if (it2 != ord[0].begin() && next(it) != st.end() &&
        dsu.find(back[*prev(it2)][0]) == dsu.find(back[*next(it)][0])) {
      if (!dsu.join(back[*next(it)][0], i)) puts("LIXO2");
      ++it, st.erase(prev(it));
    }
    for (int j = 1; j < k; j++) {
      it2 = ord[j].insert(a[i][j]).first;
      if (it2 != ord[j].begin()) {
        int p = dsu.find(back[*prev(it2)][j]), eu = dsu.find(i);
        if (a[p][0] > a[eu][0]) {
          assert(st.count(a[eu][0]));
          vector<int> rm;
          for (auto it3 = st.find(a[eu][0]);
               it3 != st.end() && back[*it3][0] != p; ++it3) {
            if (!dsu.join(p, back[*it3][0])) puts("LIXO3");
            rm.push_back(back[*it3][0]);
          }
          for (int x : rm) st.erase(a[x][0]);
        }
      }
      if (next(it2) != ord[j].end()) {
        int p = dsu.find(i), eu = dsu.find(back[*next(it2)][j]);
        if (a[p][0] > a[eu][0]) {
          vector<int> rm;
          assert(st.count(a[eu][0]));
          for (auto it3 = st.find(a[eu][0]);
               it3 != st.end() && back[*it3][0] != p; ++it3) {
            if (!dsu.join(p, back[*it3][0])) puts("LIXO4");
            rm.push_back(back[*it3][0]);
          }
          for (int x : rm) st.erase(a[x][0]);
        }
      }
    }
    printf("%d\n", dsu.sz[dsu.find(back[*st.rbegin()][0])]);
  }
}
