#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
pair<int,int> a[100005];
int start[100005];
int end[100005];
int dop;
int used[100005];
int endt[100005];
int ans[100005];
vector<int> g[100005];
int T;
bool cmp(const int &x,const int &y){
	if (endt[x]<endt[y]){
		return false;
	}
	else{
		return true;
	}
}
void dfs(int x){
	used[x]=true;
	for (int i=0;i<g[x].size();i++){
		if (used[g[x][i]]==0){
			dfs(g[x][i]);
		}
	}
	T++;
	endt[x]=T;
	return;
}
int pl,x;
int main()
{
	//cout<<"!";
	cin>>n>>m;
	//cout<<n<<m<<endl;
	for (int i=1;i<=n;i++){
		start[i]=pl+1;
		for (int j=1;j<=m;j++){
			cin>>x;
			if (x<0){
				continue;
			}
			pl++;
			a[pl].first=x;
			a[pl].second=j;
		}
		end[i]=pl;
		/*for (int j=start[i];j<=end[i];j++){
			cout<<a[j].first<<" "<<a[j].second<<endl;
		}*/
		sort(a+start[i],a+end[i]+1);
/*		for (int j=start[i];j<=end[i];j++){
			cout<<a[j].first<<" "<<a[j].second<<endl;
		}*/
	}
	dop=m+1;
	for (int i=1;i<=n;i++){
		int L=start[i];
		int R=end[i];
		//cout<<"L="<<L<<"R="<<R<<endl;
		for (int j=L;j<=R;j++){
			int samef=j;
			int samet=j;
			int k;
			for (k=samef+1;k<=R;k++){
				if (a[k].first==a[samef].first){
					samet++;
				}
				else{
					break;
				}
			}
			j=samet;
		//	cout<<samef<<" "<<samet<<endl;
			for (int k=samef;k<=samet;k++){
				if (samef>L){
		//			cout<<"!";
					g[dop-1].push_back(a[k].second);
				}
				if (samet<R){
		//			cout<<"?";
					g[a[k].second].push_back(dop);
				}
			}
			//cout<<endl;
			if (samet<R){
				dop++;
			}
		}
	}
	/*for (int i=1;i<dop;i++){
		cout<<i<<":"<<" ";
		for (int j=0;j<g[i].size();j++){
			cout<<g[i][j]<<" ";
		}
		cout<<endl;
	}*/
	for (int i=1;i<dop;i++){
		if (used[i]==0){
			dfs(i);
		}
	}
	//cout<<"!"<<endl;
	/*for (int i=1;i<dop;i++){
		cout<<endt[i]<<" ";
	}
	cout<<endl;*/
	for (int i=1;i<dop;i++){
		for (int j=0;j<g[i].size();j++){
			if (endt[i]<endt[g[i][j]]){
				cout<<-1;
				return 0;
			}
		}
	}
	for (int i=1;i<=m;i++){
		ans[i]=i;
	}

	sort(ans+1,ans+m+1,cmp);
//	cout<<"?";
	for (int i=1;i<=m;i++){
		cout<<ans[i]<<" ";
	}
    return 0;
}


#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
pair<int,int> a[100005];
int start[100005];
int end[100005];
int dop;
int used[100005];
int endt[100005];
int ans[100005];
vector<int> g[100005];
int T;
bool cmp(const int &x,const int &y){
	if (endt[x]<endt[y]){
		return false;
	}
	else{
		return true;
	}
}
void dfs(int x){
	used[x]=true;
	for (int i=0;i<g[x].size();i++){
		if (used[g[x][i]]==0){
			dfs(g[x][i]);
		}
	}
	T++;
	endt[x]=T;
	return;
}
int pl,x;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		start[i]=pl+1;
		for (int j=1;j<=m;j++){
			cin>>x;
			if (x<0){
				continue;
			}
			pl++;
			a[pl].first=x;
			a[pl].second=j;
		}
		end[i]=pl;
		sort(a+start[i],a+end[i]+1);
	}
	dop=m+1;
	for (int i=1;i<=n;i++){
		int L=start[i];
		int R=end[i];
		for (int j=L;j<=R;j++){
			int samef=j;
			int samet=j;
			for (int k=samef+1;k<=R;k++){
				if (a[k].first==a[samef].first){
					samet++;
				}
				else{
					j=k-1;
					break;
				}
			}
			for (int k=samef;k<=samet;k++){
				if (samef>L){
					g[dop-1].push_back(a[k].second);
				}
				if (samet<R){
					g[a[k].second].push_back(dop);
				}
			}
			if (samet<R){
				dop++;
			}
		}
	}
	for (int i=1;i<dop;i++){
		if (used[i]==0){
			dfs(i);
		}
	}
	for (int i=1;i<dop;i++){
		for (int j=0;j<g[i].size();j++){
			if (endt[i]<endt[g[i][j]]){
				cout<<-1;
				return 0;
			}
		}
	}
	for (int i=1;i<=m;i++){
		ans[i]=i;
	}
	sort(ans+1,ans+m+1,cmp);
	for (int i=1;i<=m;i++){
		cout<<ans[i]<<" ";
	}
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<ctime>
#include<cfloat>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<string>
#include<stack>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<time.h>
#include<bitset>
#include<list>
#include<utility>
#include<bitset>
#include<sstream>
#include<iomanip>
#include<complex>
#include<ctime>
#include<fstream>
using namespace std;
int n,m;
pair<int,int> a[100005];
int start[100005];
int end[100005];
int dop;
int used[100005];
int endt[100005];
int ans[100005];
vector<int> g[100005];
int T;
bool cmp(const int &x,const int &y){
	if (endt[x]<endt[y]){
		return false;
	}
	else{
		return true;
	}
}
void dfs(int x){
	used[x]=true;
	for (int i=0;i<g[x].size();i++){
		if (used[g[x][i]]==0){
			dfs(g[x][i]);
		}
	}
	T++;
	endt[x]=T;
	return;
}
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			int pl=i*n+j;
			if (j==1){
				start[i]=pl;
			}
			else if (j==m){
				end[i]=pl;
			}
			cin>>a[pl].first;
			a[pl].second=j;
		}
		sort(a+start[i],a+end[i]);
	}
	dop=n*m+1;
	for (int i=1;i<=n;i++){
		int L=start[i];
		int R=end[i];
		for (int j=L;j<=R;j++){
			int samef=j;
			int samet=j;
			for (int k=samef;k<=R;k++){
				if (a[k]==a[samef]){
					samef++;
				}
				else{
					j=k;
					break;
				}
			}
			for (int k=samef;k<=samet;k++){
				if (samef>L){
					g[dop-1].push_back(a[k].second);
				}
				if (samet<R){
					g[a[k].second].push_back(dop);
				}
			}
			if (samet<R){
				dop++;
			}
		}
	}
	for (int i=1;i<dop;i++){
		if (used[i]==0){
			dfs(i);
		}
	}
	for (int i=1;i<dop;i++){
		for (int j=0;j<g[i].size();j++){
			if (endt[i]<endt[g[i][j]]){
				cout<<-1;
				return 0;
			}
		}
	}
	for (int i=1;i<=m;i++){
		ans[i]=i;
	}
	sort(ans+1,ans+m+1,cmp);
	for (int i=1;i<=m;i++){
		cout<<ans[i]<<" ";
	}
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <set>

#define FOR(i, s, e) for (int i=(s);i<(e);i++)
#define FOE(i, s, e) for (int i=(s);i<=(e);i++)
#define FOD(i, s, e) for (int i=(s)-1;i>=(e);i--)
#define CLR(x, a) memset(x, a, sizeof(x))
#define LL long long int

#define N 100005
using namespace std;

vector <int> V[N];

int n, m, x, imposs, pre;

bool cmp(vector <int> A, vector <int> B){
    FOR(i, 0, n)
        if (A[i] != -1 && B[i] != -1 && A[i] != B[i])
            return A[i] < B[i];
    FOR(i, 0, n){
        if (A[i] == -1 && B[i] != -1) A[i] = B[i];
        if (B[i] == -1 && A[i] != -1) B[i] = A[i];
    }
    return 0;
}

int main(){
    scanf("%d%d", &n, &m);
    FOR(i, 0, n)
    FOR(j, 0, m){
        scanf("%d", &x);
        V[j].push_back(x);
    }
    FOR(j, 0, m) V[j].push_back(j);

    sort(V, V + m, cmp);

    imposs = 0;

    FOR(i, 0, n){
        pre = -1;
        FOR(j, 0, m){
            if (V[j][i] == -1) continue;
            if (pre > V[j][i]){
                imposs = 1;
                break;
            }
            pre = V[j][i];
        }
        if (imposs) break;
    }

    if (imposs) printf("-1\n");
    else
        FOR(i, 0, m) printf("%d%c", V[i][n] + 1, i==m-1?'\n':' ');

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <set>

#define FOR(i, s, e) for (int i=(s);i<(e);i++)
#define FOE(i, s, e) for (int i=(s);i<=(e);i++)
#define FOD(i, s, e) for (int i=(s)-1;i>=(e);i--)
#define CLR(x, a) memset(x, a, sizeof(x))
#define LL long long int

#define N 300005
using namespace std;

struct Pt{
    int x, y;
    bool operator < (const Pt & T) const {return y < T.y;}
}P[N];

int n, v[N], V, qd[N], qn[N], l[N], E, stk[N], m, t, imposs, fir;

void bd(int x, int y){qd[E] = y; qn[E] = l[x]; l[x] = E++;}

void DFS(int x){
    if (v[x] == 1) {
        imposs = 1;
        return;
    }
    v[x] = 1;
    for (int k=l[x];k!=-1;k=qn[k]) if (v[qd[k]] != 2) DFS(qd[k]);
    stk[--t] = x;
    v[x] = 2;
}

int main(){
    scanf("%d%d", &n, &m);

    V = m;
    CLR(l, -1); E = 0;

    FOR(i, 0, n){
        FOR(j, 0, m){
            scanf("%d", &P[j].y);
            P[j].x = j;
        }
        sort(P, P + m);
        fir = 0;
        V++;
        FOR(j, 0, m){

            if (P[j].y == -1) continue;

            if (!j || P[j].y != P[j-1].y){
                bd(P[j].x, V++);
                fir = 1;
            }
            else bd(P[j].x, V - 1);

            bd(V - 2, P[j].x);
        }
    }

    CLR(v, 0);
    t = V;
    imposs = 0;
    FOR(i, 0, V) if (!v[i]) DFS(i);

    if (imposs) printf("-1\n");
    else {
        for (int i=0,cnt=0;i<V;i++)
            if (stk[i] < m)
                printf("%d%c", stk[i] + 1, (++cnt == m) ? '\n':' ');
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <set>

#define FOR(i, s, e) for (int i=(s);i<(e);i++)
#define FOE(i, s, e) for (int i=(s);i<=(e);i++)
#define FOD(i, s, e) for (int i=(s)-1;i>=(e);i--)
#define CLR(x, a) memset(x, a, sizeof(x))
#define LL long long int

#define N 100005
using namespace std;

vector <int> V[N], T[N];

int n, m, x, imposs, pre, stk[N], t, l[N], qd[N * 30], qn[N * 30], E = 0, v[N];

void bd(int x, int y){qd[E] = y; qn[E] = l[x]; l[x] = E++;}

bool cmp(vector<int> A, vector<int> B){
    FOR(i, 0, n)
        if (A[i] != -1 && B[i] != -1 && A[i] != B[i]){
            if (A[i] < B[i]) bd(A[n], B[n]);
            else bd(B[n], A[n]);
            return A[i] < B[i];
        }
    return 0;
}

void DFS(int x){
    v[x] = 1;
    for (int k=l[x];k!=-1;k=qn[k]) if (!v[qd[k]]) DFS(qd[k]);
    stk[--t] = x;
}

int main(){
    scanf("%d%d", &n, &m);
    FOR(i, 0, n)
    FOR(j, 0, m){
        scanf("%d", &x);
        V[j].push_back(x);
    }
    FOR(j, 0, m){
        V[j].push_back(j);
        T[j] = V[j];
    }
    CLR(l, -1);

    sort(V, V + m, cmp);

    t = m;
    FOR(i, 0, m) if (!v[i]) DFS(i);

    //FOR(i, 0, m) printf("STK [%d] = %d\n", i, stk[i]);

    imposs = 0;

    FOR(i, 0, n){
        pre = -1;
        FOR(j, 0, m){
            if (T[stk[j]][i] == -1) continue;
            if (pre > T[stk[j]][i]){
                imposs = 1;
                break;
            }
            pre = T[stk[j]][i];
        }
        if (imposs) break;
    }

    if (imposs) printf("-1\n");
    else
        FOR(i, 0, m) printf("%d%c", stk[i] + 1, i==m-1?'\n':' ');

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <set>

#define FOR(i, s, e) for (int i=(s);i<(e);i++)
#define FOE(i, s, e) for (int i=(s);i<=(e);i++)
#define FOD(i, s, e) for (int i=(s)-1;i>=(e);i--)
#define CLR(x, a) memset(x, a, sizeof(x))
#define LL long long int

#define N 200005
using namespace std;

struct Pt{
    int x, y;
    bool operator < (const Pt & T) const {return y < T.y;}
}P[N];

int n, v[N], V, qd[N], qn[N], l[N], E, stk[N], m, t, imposs;

void bd(int x, int y){qd[E] = y; qn[E] = l[x]; l[x] = E++;}

void DFS(int x){
    if (v[x] == 1) {
        imposs = 1;
        return;
    }
    v[x] = 1;
    for (int k=l[x];k!=-1;k=qn[k]) if (v[qd[k]] != 2) DFS(qd[k]);
    stk[--t] = x;
    v[x] = 2;
}

int main(){
    scanf("%d%d", &n, &m);

    V = m;
    CLR(l, -1); E = 0;

    FOR(i, 0, n){
        FOR(j, 0, m){
            scanf("%d", &P[j].y);
            P[j].x = j;
        }
        sort(P, P + m);
        int fir = 0;
        FOR(j, 0, m){
            if (P[j].y == -1) continue;
            if (!j || P[j].y != P[j-1].y){
                if (fir) bd(V - 1, P[j].x);
                bd(P[j].x, V++);
                fir = 1;
            }
            else bd(P[j].x, V - 1);
        }
    }

    CLR(v, 0);
    t = V;
    imposs = 0;
    FOR(i, 0, V) if (!v[i]) DFS(i);

    if (imposs) printf("-1\n");
    else {
        for (int i=0,cnt=0;i<V;i++)
            if (stk[i] < m)
                printf("%d%c", stk[i] + 1, (++cnt == m) ? '\n':' ');
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <set>

#define FOR(i, s, e) for (int i=(s);i<(e);i++)
#define FOE(i, s, e) for (int i=(s);i<=(e);i++)
#define FOD(i, s, e) for (int i=(s)-1;i>=(e);i--)
#define CLR(x, a) memset(x, a, sizeof(x))
#define LL long long int

#define N 100005
using namespace std;

vector <int> V[N], T[N];

int n, m, x, imposs, pre, stk[N], t, l[N], qd[N * 30], qn[N * 30], E = 0, v[N];

void bd(int x, int y){qd[E] = y; qn[E] = l[x]; l[x] = E++;}

bool cmp(vector<int> A, vector<int> B){
    FOR(i, 0, n)
        if (A[i] != -1 && B[i] != -1 && A[i] != B[i]){
            if (A[i] < B[i]) bd(B[n], A[n]);
            else bd(A[n], B[n]);
            return A[i] < B[i];
        }
    bd(B[n], A[n]);
    return 0;
}

void DFS(int x){
    v[x] = 1;
    for (int k=l[x];k!=-1;k=qn[k]) if (!v[qd[k]]) DFS(qd[k]);
    stk[t++] = x;
}

int main(){
    scanf("%d%d", &n, &m);
    FOR(i, 0, n)
    FOR(j, 0, m){
        scanf("%d", &x);
        V[j].push_back(x);
    }
    FOR(j, 0, m){
        V[j].push_back(j);
        T[j] = V[j];
    }
    CLR(l, -1);

    sort(V, V + m, cmp);

    //FOR(i, 0, n) FOR(j, 0, m) printf("%d%c", V[j][i], j==m-1?'\n':' ');

    t = 0;
    FOR(i, 0, m) if (!v[i]) DFS(i);

    //FOR(i, 0, m) printf("STK [%d] = %d\n", i, stk[i]);

    imposs = 0;

    FOR(i, 0, n){
        pre = -1;
        FOR(j, 0, m){
            if (T[stk[j]][i] == -1) continue;
            if (pre > T[stk[j]][i]){
                imposs = 1;
                break;
            }
            pre = T[stk[j]][i];
        }
        if (imposs) break;
    }

    if (imposs) printf("-1\n");
    else
        FOR(i, 0, m) printf("%d%c", stk[i] + 1, i==m-1?'\n':' ');

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define M 100100
using namespace std;

int n,m,join[10*M],cnt,ans[M],tot;
vector<int>v[M];
queue<int>q;

struct node{int val,no;}rec[M];

bool cmp(node a,node b){return a.val<b.val;}

void add(int x,int y){join[y]++;v[x].push_back(y);}

int main()
{
    cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) scanf("%d",&rec[j].val),rec[j].no=j;
		sort(rec+1,rec+m+1,cmp);
		for(int j=1;j<=m;j++)
		{
			if(rec[j].val<0) continue;
			if(j==1||rec[j].val!=rec[j-1].val) cnt++;
			add(m+cnt,rec[j].no);add(rec[j].no,m+cnt+1);
		}
		cnt++;
	}
	for(int i=1;i<=m+cnt;i++)if(!join[i]) q.push(i);
	while(!q.empty())
	{
		int t=q.front();q.pop();
		if(t<=m) ans[++tot]=t;
		for(int i=0;i<v[t].size();i++)
		{
			int tmp=v[t][i];
			join[tmp]--;
			if(!join[tmp]) q.push(tmp);
		}
	}
	if(tot<m) {cout<<-1;return 0;}
	for(int i=1;i<=m;i++)printf("%d ",ans[i]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define M 100100
using namespace std;

int n,m,join[2*M],cnt,ans[M],tot;
vector<int>v[M];
queue<int>q;

struct node{int val,no;}rec[M];

bool cmp(node a,node b){return a.val<b.val;}

void add(int x,int y){join[y]++;v[x].push_back(y);}

int main()
{
    cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) scanf("%d",&rec[j].val),rec[j].no=j;
		sort(rec+1,rec+m+1,cmp);
		for(int j=1;j<=m;j++)
		{
			if(rec[j].val<0) continue;
			if(!j||rec[j].val!=rec[j-1].val) cnt++;
			add(m+cnt,rec[j].no);add(rec[j].no,m+cnt+1);
		}
		cnt++;
	}
	for(int i=1;i<=m+cnt;i++)if(!join[i]) q.push(i);
	while(!q.empty())
	{
		int t=q.front();q.pop();
		if(t<=m) ans[++tot]=t;
		for(int i=0;i<v[t].size();i++)
		{
			int tmp=v[t][i];
			join[tmp]--;
			if(!join[tmp]) q.push(tmp);
		}
	}
	if(tot<m) {cout<<-1;return 0;}
	for(int i=1;i<=m;i++)printf("%d ",ans[i]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define M 100100
using namespace std;

int n,m,join[2*M],cnt,ans[M],tot;
vector<int>v[M];
queue<int>q;

struct node{int val,no;}rec[M];

bool cmp(node a,node b){return a.val<b.val;}

void add(int x,int y){printf("%d %d\n",x,y);join[y]++;v[x].push_back(y);}

int main()
{
    cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) scanf("%d",&rec[j].val),rec[j].no=j;
		sort(rec+1,rec+m+1,cmp);
		for(int j=1;j<=m;j++)
		{
			if(rec[j].val<0) continue;
			if(!j||rec[j].val!=rec[j-1].val) cnt++;
			add(m+cnt,rec[j].no);add(rec[j].no,m+cnt+1);
		}
		cnt++;
	}
	for(int i=1;i<=m+cnt;i++)if(!join[i]) q.push(i);
	while(!q.empty())
	{
		int t=q.front();q.pop();
		if(t<=m) ans[++tot]=t;
		for(int i=0;i<v[t].size();i++)
		{
			int tmp=v[t][i];
			join[tmp]--;
			if(!join[tmp]) q.push(tmp);
		}
	}
	if(tot<m) {cout<<-1;return 0;}
	for(int i=1;i<=m;i++)printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 500005;

int N, M;
vector< pair< int, int > > V[ maxn ]; // vrijednost, stupac

vector< int > graf[ maxn ];
vector< int > redoslijed;

int t;
int bio[ maxn  ];
int indegree[ maxn ], postoji[ maxn ];

bool greska = false;

void dfs( int cvor ){
    //if( bio[ cvor ] ){ greska = true; return; }
//printf( "dosao sam na cvor %d\n", cvor );
    redoslijed.push_back( cvor );
    bio[ cvor ] = 1;
    for( int i = 0; i < graf[ cvor ].size(); i ++ ){
        indegree[ graf[ cvor ][ i ] ] --;
        if( indegree[ graf[ cvor ][ i ] ] == 0 ) dfs( graf[ cvor ][ i ] );
    }
}

void rijesi(){
    for( int i = 0; i < N; i ++ )
        sort( V[ i ].begin(), V[ i ].end() );

    int D = M;
    for( int i = 0; i < N; i ++ ){
        if( V[ i ][ 0 ].first != -1 && V[ i ][ 0 ].first != V[ i ][ M - 1 ].first ){ graf[ D ].push_back( V[ i ][ 0 ].second ); indegree[ V[ i ][ 0 ].second ] ++; }

        for( int j = 1; j < M; j ++ ){
            if( V[ i ][ j ].first != V[ i ][ j - 1 ].first ){
                for( int k = j; k < M && V[ i ][ k ].first == V[ i ][ j ].first; k ++ ){
                    graf[ V[ i ][ k ].second ].push_back( D );
                    indegree[ D ] ++;

                    postoji[ D ] = postoji[ V[ i ][ k ].second ] = 1;
                }
                D ++;
            }
            if( V[ i ][ j ].first != V[ i ][ M - 1 ].first ){
                graf[ D ].push_back( V[ i ][ j ].second );
                indegree[ V[ i ][ j ].second ] ++;

                postoji[ D ] = postoji[ V[ i ][ j ].second ] = 1;
            }
        }
    }

    for( int i = 0; i < M; i ++ )
        if( !bio[ i ] && indegree[ i ] == 0 ) dfs( i );

    for( int i = 0; i < M; i ++ )
        if( !bio[ i ] ) greska = true;
}

void ispisi(){
    if( greska ){ printf( "-1" ); return; }
    else{
        for( int i = redoslijed.size() - 1; i >= 0; i -- )
            if( redoslijed[ i ] < M ) printf( "%d ", redoslijed[ i ] + 1 );
    }
}

void ucitaj(){
    scanf( "%d%d", &N, &M );
    for( int i = 0; i < N; i ++ ){
        for( int j = 0; j < M; j ++ ){
            int x;
            scanf( "%d", &x );

            V[ i ].push_back( make_pair( x, j ) );
        }
    }
}

int main( void ){
    ucitaj();
    rijesi();
    ispisi();

return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 500005;

int N, M;
vector< pair< int, int > > V[ maxn ]; // vrijednost, stupac

vector< int > graf[ maxn ];
vector< int > redoslijed;

int t;
int bio[ maxn  ];
int indegree[ maxn ], postoji[ maxn ];

bool greska = false;

void dfs( int cvor ){
    //if( bio[ cvor ] ){ greska = true; return; }
   // printf( "dosao sam na cvor %d\n", cvor );
    redoslijed.push_back( cvor );
    bio[ cvor ] = 1;
    for( int i = 0; i < graf[ cvor ].size(); i ++ ){
        indegree[ graf[ cvor ][ i ] ] --;
        if( indegree[ graf[ cvor ][ i ] ] == 0 ) dfs( graf[ cvor ][ i ] );
    }
}

void rijesi(){
    for( int i = 0; i < N; i ++ )
        sort( V[ i ].begin(), V[ i ].end() );

    int D = M;
    for( int i = 0; i < N; i ++ ){
        if( V[ i ][ 0 ].first != -1 && V[ i ][ 0 ].first != V[ i ][ M - 1 ].first ){ graf[ D ].push_back( V[ i ][ 0 ].second ); indegree[ V[ i ][ 0 ].second ] ++; }

        for( int j = 1; j < M; j ++ ){
            if( V[ i ][ j ].first != V[ i ][ j - 1 ].first ){
                for( int k = j; k < M && V[ i ][ k ].first == V[ i ][ j ].first; k ++ ){
                    graf[ V[ i ][ k ].second ].push_back( D );
                    indegree[ D ] ++;

                    postoji[ D ] = postoji[ V[ i ][ k ].second ] = 1;
                }
                D ++;
            }
            if( V[ i ][ j ].first != V[ i ][ M - 1 ].first ){
                graf[ D ].push_back( V[ i ][ j ].second );
                indegree[ V[ i ][ j ].second ] ++;

                postoji[ D ] = postoji[ V[ i ][ j ].second ] = 1;
            }
        }
    }

    for( int i = 0; i < maxn; i ++ )
        if( postoji[ i ] && !bio[ i ] && indegree[ i ] == 0 ) dfs( i );

    for( int i = 0; i < maxn; i ++ )
        if( postoji[ i ] && !bio[ i ] ) greska = true;
}

void ispisi(){
    if( greska ){ printf( "-1" ); return; }
    else{
        for( int i = redoslijed.size() - 1; i >= 0; i -- )
            if( redoslijed[ i ] < M ) printf( "%d ", redoslijed[ i ] + 1 );
    }
}

void ucitaj(){
    scanf( "%d%d", &N, &M );
    for( int i = 0; i < N; i ++ ){
        for( int j = 0; j < M; j ++ ){
            int x;
            scanf( "%d", &x );

            V[ i ].push_back( make_pair( x, j ) );
        }
    }
}

int main( void ){
    ucitaj();
    rijesi();
    ispisi();

return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 500005;

int N, M;
vector< pair< int, int > > V[ maxn ]; // vrijednost, stupac

vector< int > graf[ maxn ];
vector< int > redoslijed;

int t;
int bio[ maxn  ];
int indegree[ maxn ], postoji[ maxn ];

bool greska = false;

void dfs( int cvor ){
    //if( bio[ cvor ] ){ greska = true; return; }
//printf( "dosao sam na cvor %d\n", cvor );
    redoslijed.push_back( cvor );

    bio[ cvor ] = 1;
    for( int i = 0; i < graf[ cvor ].size(); i ++ ){
        indegree[ graf[ cvor ][ i ] ] --;
        if( indegree[ graf[ cvor ][ i ] ] == 0 ) dfs( graf[ cvor ][ i ] );
    }
}

void rijesi(){
    for( int i = 0; i < N; i ++ )
        sort( V[ i ].begin(), V[ i ].end() );

    int D = M;
    for( int i = 0; i < N; i ++ ){
        if( V[ i ][ 0 ].first != -1 && V[ i ][ 0 ].first != V[ i ][ M - 1 ].first ){
            graf[ D ].push_back( V[ i ][ 0 ].second );
            indegree[ V[ i ][ 0 ].second ] ++;
        }
        int zadnji = V[ i ][ 0 ].first;
        for( int j = 1; j < M; j ++ ){
            if( zadnji == -1 ) zadnji = V[ i ][ j ].first;
            if( zadnji == -1 ) continue;

            if( V[ i ][ j ].first != V[ i ][ j - 1 ].first ){
                for( int k = j; k < M && V[ i ][ k ].first == V[ i ][ j ].first; k ++ ){
                    graf[ V[ i ][ k ].second ].push_back( D );
                    indegree[ D ] ++;
                }
                zadnji = V[ i ][ j ].first;
                D ++;
            }
            if( V[ i ][ j ].first != V[ i ][ M - 1 ].first ){
                graf[ D ].push_back( V[ i ][ j ].second );
                indegree[ V[ i ][ j ].second ] ++;
            }
        }
    }

    for( int i = 0; i < M; i ++ )
        if( !bio[ i ] && indegree[ i ] == 0 ) dfs( i );
    for( int i = 0; i < M; i ++ )
        if( !bio[ i ] ) greska = true;
}

void ispisi(){
    if( greska ){ printf( "-1" ); return; }
    else{
        for( int i = redoslijed.size() - 1; i >= 0; i -- )
            if( redoslijed[ i ] < M ) printf( "%d ", redoslijed[ i ] + 1 );
    }
}

void ucitaj(){
    scanf( "%d%d", &N, &M );
    for( int i = 0; i < N; i ++ ){
        for( int j = 0; j < M; j ++ ){
            int x;
            scanf( "%d", &x );

            V[ i ].push_back( make_pair( x, j ) );
        }
    }
}

int main( void ){
    ucitaj();
    rijesi();
    ispisi();

return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 200010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N],tot;
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N],h[N];
bool cmp(g a,g b)
{
	if (a.l==b.l)
	return a.id>b.id;
	return a.l<b.l;
}
void up(int x)
{
	g t;
	while (x>1)
	{
		if (h[x].r<h[x/2].r)
		{
			t=h[x];h[x]=h[x/2];h[x/2]=t;
			x=x/2;
		}
		else
		break;
	}
}
void down(int x)
{
	int t;
	g tt;
	t=x;
	if ((2*x<=tot)&&(h[2*x].r<h[t].r)) t=2*x;
	if ((2*x+1<=tot)&&(h[2*x+1].r<h[t].r)) t=2*x+1;
	if (t!=x)
	{
		tt=h[x];h[x]=h[t];h[t]=tt;
		down(t);
	}
}
void ins(g x)
{
	tot++;
	h[tot]=x;
	up(tot);
}
void del()
{
	h[1]=h[tot];
	tot--;
	down(1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2100000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=upper_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			R=m-b[i].size()+R;
			l=max(l,L);
			r=min(r,R);
			if (l>r)
			{
				printf("-1");
				return 0;
			}
		}
	}

		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);

	j=1;
	for (i=1;i<=m;i++)
	{
		while (A[j].l==i)
		{
			ins(A[j]);
			j++;
		}
		if ((h[1].r<i)||(tot==0))
		{
			printf("-1");
			return 0;
		}
		else
		{
			ans[i]=h[1].id;
			del();
		}
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 100010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N];
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N];
bool cmp(g a,g b)
{
	if (a.l==b.l)
	return a.r<b.r;
	return a.l<b.l;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(10000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=m-(b[i].end()-upper_bound(b[i].begin(),b[i].end(),a[j][i]));
			l=max(l,L);
			r=min(r,R);
		}
	}

		if (l>r)
		{
			printf("-1");
			return 0;
		}
		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);
	for (i=1;i<=m;i++)
	if (A[i].l>i)
	{
		printf("-1");
		return 0;
	}
	else
	ans[i]=A[i].id;
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<algorithm>
#define N 2000010
using namespace std;
int n,m,tot,i,j,b[N],rd[N],a[N],dp,o,w,t,z[N];
int pre[N],p[N],tt[N],ans[N];
bool cmp(int x,int y)
{
    return a[x]<a[y];
}
void link(int x,int y)
{
    dp++;pre[dp]=p[x];p[x]=dp;tt[dp]=y;
}
int main()
{
    scanf("%d%d",&n,&m);
    tot=m;
    for (i=1;i<=n;i++)
    {
    for (j=1;j<=m;j++)
    {
        scanf("%d",&a[j]);
        b[j]=j;
    }
    sort(b+1,b+1+m,cmp);
    tot++;
    for (j=1;j<=m;j++)
    if (a[b[j]]!=-1)
    {
        link(tot,b[j]);rd[b[j]]++;
        link(b[j],tot+1);rd[tot+1]++;
        if (a[b[j]]!=a[b[j+1]]) tot++;
    }
    }

    for (i=1;i<=tot;i++)
    if (rd[i]==0)
    {
        w++;z[w]=i;
    }

    while (t!=w)
    {
        t++;
        if ((1<=z[t])&&(z[t]<=m))
        {
            o++;ans[o]=z[t];
        }
        i=p[z[t]];
        while (i)
        {
            rd[tt[i]]--;
            if (rd[tt[i]]==0)
            {
                w++;z[w]=tt[i];
            }
            i=pre[i];
        }
    }
    if (o==m)
    for (i=1;i<=o;i++)
    printf("%d ",ans[i]);
    else
    printf("-1");

}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 500010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N];
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N];
bool cmp(g a,g b)
{
	if (a.l==b.l)
	return a.r<b.r;
	return a.l<b.l;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2000000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=m-(b[i].end()-upper_bound(b[i].begin(),b[i].end(),a[j][i]));
			l=max(l,L);
			r=min(r,R);
		}
	}

		if (l>r)
		{
			printf("-1");
			return 0;
		}
		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);
	for (i=1;i<=m;i++)
	if ((A[i].l<=i)&&(A[i].r>=i))
	ans[i]=A[i].id;
	else
	{
		printf("-1");
		return 0;
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 200010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N],tot;
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N],h[N];
bool cmp(g a,g b)
{
	return a.l<b.l;
}
void up(int x)
{
	g t;
	while (x>1)
	{
		if (h[x].r<h[x/2].r)
		{
			t=h[x];h[x]=h[x/2];h[x/2]=t;
			x=x/2;
		}
		else
		break;
	}
}
void down(int x)
{
	int t;
	g tt;
	t=x;
	if ((2*x<=tot)&&(h[2*x].r<h[t].r)) t=2*x;
	if ((2*x+1<=tot)&&(h[2*x+1].r<h[t].r)) t=2*x+1;
	if (t!=x)
	{
		tt=h[x];h[x]=h[t];h[t]=tt;
		down(t);
	}
}
void ins(g x)
{
	tot++;
	h[tot]=x;
	up(tot);
}
void del()
{
	h[1]=h[tot];
	tot--;
	down(1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2000000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=upper_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			R=m-b[i].size()+R;
			l=max(l,L);
			r=min(r,R);
			if (l>r)
			{
				printf("-1");
				return 0;
			}
		}
	}

		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);

	j=1;
	for (i=1;i<=m;i++)
	{
		while (A[j].l==i)
		{
			ins(A[j]);
			j++;
		}
		if ((h[1].r<i)||(tot==0))
		{
			printf("-1");
			return 0;
		}
		else
		{
			ans[i]=h[1].id;
			del();
		}
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 500010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N],tot;
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N],h[N];
bool cmp(g a,g b)
{
	return a.l<b.l;
}
void up(int x)
{
	g t;
	while (x>1)
	{
		if (h[x].r<h[x/2].r)
		{
			t=h[x];h[x]=h[x/2];h[x/2]=t;
			x=x/2;
		}
		else
		break;
	}
}
void down(int x)
{
	int t;
	g tt;
	t=x;
	if ((2*x<=tot)&&(h[2*x].r<h[t].r)) t=2*x;
	if ((2*x+1<=tot)&&(h[2*x+1].r<h[t].r)) t=2*x+1;
	if (t!=x)
	{
		tt=h[x];h[x]=h[t];h[t]=tt;
		down(t);
	}
}
void ins(g x)
{
	tot++;
	h[tot]=x;
	up(tot);
}
void del()
{
	h[1]=h[tot];
	tot--;
	down(1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2000000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=m-(b[i].end()-upper_bound(b[i].begin(),b[i].end(),a[j][i]));
			l=max(l,L);
			r=min(r,R);
			if (l>r)
			{
				printf("-1");
				return 0;
			}
		}
	}

		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);

	j=1;
	for (i=1;i<=m;i++)
	{
		while (A[j].l==i)
		{
			ins(A[j]);
			j++;
		}
		if (h[1].r<i)
		{
			printf("-1");
			return 0;
		}
		else
		{
			ans[i]=h[1].id;
			del();
		}
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<algorithm>
#define N 100010
using namespace std;
int n,m,tot,i,j,b[N],rd[N],a[N],dp,o,w,t,z[N];
int pre[N],p[N],tt[N],ans[N];
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
void link(int x,int y)
{
	dp++;pre[dp]=p[x];p[x]=dp;tt[dp]=y;
}
int main()
{
	scanf("%d%d",&n,&m);
	tot=m;
	for (i=1;i<=n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&a[j]);
		b[j]=j;
	}
	sort(b+1,b+1+m,cmp);
	tot++;
	for (j=1;j<=m;j++)
	if (a[b[j]]!=-1)
	{
		link(tot,b[j]);rd[b[j]]++;
		link(b[j],tot+1);rd[tot+1]++;
		if (a[b[j]]!=a[b[j+1]]) tot++;
	}
	}

	for (i=1;i<=tot;i++)
	if (rd[i]==0)
	{
		w++;z[w]=i;
	}

	while (t!=w)
	{
		t++;
		if ((1<=z[t])&&(z[t]<=m))
		{
			o++;ans[o]=z[t];
		}
		i=p[z[t]];
		while (i)
		{
			rd[tt[i]]--;
			if (rd[tt[i]]==0)
			{
				w++;z[w]=tt[i];
			}
			i=pre[i];
		}
	}
	if (o==m)
	for (i=1;i<=o;i++)
	printf("%d ",ans[i]);
	else
	printf("-1");

}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 200010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N],tot;
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N],h[N];
bool cmp(g a,g b)
{
	return a.l<b.l;
}
void up(int x)
{
	g t;
	while (x>1)
	{
		if (h[x].r<h[x/2].r)
		{
			t=h[x];h[x]=h[x/2];h[x/2]=t;
			x=x/2;
		}
		else
		break;
	}
}
void down(int x)
{
	int t;
	g tt;
	t=x;
	if ((2*x<=tot)&&(h[2*x].r<h[t].r)) t=2*x;
	if ((2*x+1<=tot)&&(h[2*x+1].r<h[t].r)) t=2*x+1;
	if (t!=x)
	{
		tt=h[x];h[x]=h[t];h[t]=tt;
		down(t);
	}
}
void ins(g x)
{
	tot++;
	h[tot]=x;
	up(tot);
}
void del()
{
	h[1]=h[tot];
	tot--;
	down(1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2100000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=upper_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			R=m-b[i].size()+R;
			l=max(l,L);
			r=min(r,R);
			if (l>r)
			{
				printf("-1");
				return 0;
			}
		}
	}

		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);

	j=1;
	for (i=1;i<=m;i++)
	{
		while (A[j].l==i)
		{
			ins(A[j]);
			j++;
		}
		if ((h[1].r<i)||(tot==0))
		{
			printf("-1");
			return 0;
		}
		else
		{
			ans[i]=h[1].id;
			del();
		}
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 500010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N];
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N];
bool cmp(g a,g b)
{
	if (a.l==b.l)
	return a.r<b.r;
	return a.l<b.l;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(2000000000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=m+1-(b[i].end()-upper_bound(b[i].begin(),b[i].end(),a[j][i]));
			l=max(l,L);
			r=min(r,R);
			if (l>r)
			{
				printf("-1");
				return 0;
			}
		}
	}

		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);
	for (i=1;i<=m;i++)
	if ((A[i].l<=i)&&(A[i].r>=i))
	ans[i]=A[i].id;
	else
	{
		printf("-1");
		return 0;
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define N 100010
using namespace std;
int n,m,i,j,aa,l,r,L,R,ans[N];
vector<int> a[N],b[N];
struct g{
	int l,r,id;
}A[N];
bool cmp(g a,g b)
{
	if (a.l==b.l)
	return a.r<b.r;
	return a.l<b.l;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=0;i<n;i++)
	{
	for (j=1;j<=m;j++)
	{
		scanf("%d",&aa);
		a[j].push_back(aa);
		if (aa!=-1)
		b[i].push_back(aa);
	}
	b[i].push_back(10000);
	sort(b[i].begin(),b[i].end());
	}

	for (j=1;j<=m;j++)
	{
	l=0;r=m-1;
	for (i=0;i<n;i++)
	{
		if (a[j][i]==-1)
		continue;
		else
		{
			int L=lower_bound(b[i].begin(),b[i].end(),a[j][i])-b[i].begin();
			int R=m-(b[i].end()-upper_bound(b[i].begin(),b[i].end(),a[j][i]));
			l=max(l,L);
			r=min(r,R);
		}
	}

		if (l>r)
		{
			printf("-1");
			return 0;
		}
		A[j].l=l+1;
		A[j].r=r+1;
		A[j].id=j;
	}
	sort(A+1,A+1+m,cmp);
	for (i=1;i<=m;i++)
	if ((A[i].l<=i)&&(A[i].r>=i))
	ans[i]=A[i].id;
	else
	{
		printf("-1");
		return 0;
	}
	for (i=1;i<=m;i++)
	printf("%d ",ans[i]);
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())

const int N = 1e5+5;
vector<int> srt[N], a[N], sol;
int INDEX, u[N];
int start[N], n;

bool cmp(int x, int y) {
	return a[INDEX][x] < a[INDEX][y];
}

void dfs(int x) {
	u[x] = 1;
	for(int i=0;i<n;i++) {
		if(a[i][x] == -1) continue;
		for(int j=start[i];j<SZ(srt[i]) && a[i][srt[i][j]]<a[i][x];j++,start[i]++)
			if(!u[srt[i][j]])
				dfs(srt[i][j]);
	}
	sol.push_back(x);
}

int main(void) {
	int m;
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		int x;
		scanf("%d", &x);
		a[i].push_back(x);
		if(x>=0) srt[i].push_back(j);
	}
	for(int i=0;i<n;i++) {
		INDEX = i;
		sort(srt[i].begin(), srt[i].end(), cmp);
	}
	for(int i=0;i<m;i++)
		if(u[i] == 0)
			dfs(i);
	for(int i=1;i<m;i++) {
		for(int j=0;j<n;j++)
			if(a[j][sol[i]] != -1 && a[j][sol[i-1]] != -1 && a[j][sol[i-1]] > a[j][sol[i]])
			{ puts("-1"); return 0; }
	}
	for(int i=0;i<m;i++)
		printf("%d ", sol[i]+1);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())

const int N = 1e5+5;
vector<int> srt[N], a[N], sol;
int INDEX, u[N];
int start[N], n;

bool cmp(int x, int y) {
	return a[INDEX][x] < a[INDEX][y];
}

void dfs(int x) {
	u[x] = 1;
	for(int i=0;i<n;i++) {
		if(a[i][x] == -1) continue;
		for(int j=start[i];j<SZ(srt[i]) && a[i][srt[i][j]]<a[i][x];j++,start[i]++)
			if(!u[srt[i][j]])
				dfs(srt[i][j]);
	}
	sol.push_back(x);
}

int main(void) {
	int m;
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		int x;
		scanf("%d", &x);
		a[i].push_back(x);
		if(x>=0) srt[i].push_back(j);
	}
	for(int i=0;i<n;i++) {
		INDEX = i;
		sort(srt[i].begin(), srt[i].end(), cmp);
	}
	for(int i=0;i<m;i++)
		if(u[i] == 0)
			dfs(i);
	for(int i=0;i<n;i++) {
		int last=-1;
		for(int j=0;j<m;j++) {
			if(a[i][j] == -1) continue;
			if(a[i][j] < last) { puts("-1"); return 0; }
			last = a[i][j];
		}
	}
	for(int i=0;i<m;i++)
		printf("%d ", sol[i]+1);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())

const int N = 1e5+5;
vector<int> srt[N], a[N], sol;
int INDEX, u[N];
int start[N], n;

bool cmp(int x, int y) {
	return a[INDEX][x] < a[INDEX][y];
}

void dfs(int x) {
	u[x] = 1;
	for(int i=0;i<n;i++) {
		if(a[i][x] == -1) continue;
		for(int j=start[i];j<SZ(srt[i]) && a[i][srt[i][j]]<a[i][x];j++,start[i]++)
			if(!u[srt[i][j]])
				dfs(srt[i][j]);
	}
	sol.push_back(x);
}

int main(void) {
	int m;
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		int x;
		scanf("%d", &x);
		a[i].push_back(x);
		if(x>=0) srt[i].push_back(j);
	}
	for(int i=0;i<n;i++) {
		INDEX = i;
		sort(srt[i].begin(), srt[i].end(), cmp);
	}
	for(int i=0;i<m;i++)
		if(u[i] == 0)
			dfs(i);
	for(int i=0;i<n;i++) {
		int last=-1;
		for(int j=0;j<m;j++) {
			if(a[i][sol[j]] == -1) continue;
			if(a[i][sol[j]] < last) { puts("-1"); return 0; }
			last = a[i][sol[j]];
		}
	}
	for(int i=0;i<m;i++)
		printf("%d ", sol[i]+1);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define SZ(c) ((int)(c).size())

const int N = 1e5+5;
vector<int> srt[N], a[N], sol;
int INDEX, u[N];
int start[N], n;

bool cmp(int x, int y) {
	return a[INDEX][x] < a[INDEX][y];
}

void dfs(int x) {
	u[x] = 1;
	for(int i=0;i<n;i++) {
		if(a[i][x] == -1) continue;
		for(int j=start[i];a[i][srt[i][j]]<a[i][x];j++,start[i]++)
			if(!u[srt[i][j]])
				dfs(srt[i][j]);
	}
	sol.push_back(x);
}

int main(void) {
	int m;
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		int x;
		scanf("%d", &x);
		a[i].push_back(x);
		if(x>=0) srt[i].push_back(j);
	}
	for(int i=0;i<n;i++) {
		INDEX = i;
		sort(srt[i].begin(), srt[i].end(), cmp);
	}
	for(int i=0;i<m;i++)
		if(u[i] == 0)
			dfs(i);
	for(int i=1;i<m;i++) {
		for(int j=0;j<n;j++)
			if(a[j][sol[i]] != -1 && a[j][sol[i-1]] != -1 && a[j][sol[i-1]] > a[j][sol[i]])
			{ puts("-1"); return 0; }
	}
	for(int i=0;i<m;i++)
		printf("%d ", sol[i]+1);
	return 0;
}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 1000005

using namespace std;

vector<int>v[N];
int n, m;

bool menor(int x, int y){

    for(int i = 0; i < n; i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[y][i] < v[x][i])return false;
    }

    return true;
}

int p[N];

int main(){

    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        sort(p, p + m, menor);

        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 1; j < m; j++){

                int p1 = -(1<<30);
                int p2 = v[p[j]][i];;
                int p3 = (1<<30) + 2;

                if(v[p[j - 1]][i] >= 0)p1 = v[p[j - 1]][i];
                if(j + 1 < m && v[p[j + 1]][i] >= 0)p3 = v[p[j + 1]][i];
                //cout << p1 << " " << p2 << " " << p3 << endl;
                if(p2 == -1){

                    if(!(p1 <= p3))ok = false;
                }
                else if(!(p1 <= p2 && p2 <= p3))ok = false;
            }
        }

        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 1000005

using namespace std;

vector<int>v[N];
int n, m;

bool menor(int x, int y){

    int c1 = 0, c2 = 0;
    for(int i = 0; i < n; i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[x][i] < v[y][i])c1++;
        else if(v[y][i] < v[x][i])c2++;
    }

    if(c1 == 0 && c2 == 0)return true;
    if(c1 > 0 && c2 > 0)return false;
    return c1 > 0;
}

int p[N];

int main(){

    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        sort(p, p + m, menor);

        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 1; j < m; j++){

                int p1 = -(1<<30);
                int p2;
                int p3 = (1<<30) + 2;

                if(v[p[j - 1]][i] > 0)p1 = v[p[j - 1]][i];
                p2 = v[p[j]][i];
                if(j + 1 < m && v[p[j + 1]][i] > 0)p3 = v[p[j + 1]][i];

                if(p2 == -1){

                    if(!(p1 < p3))ok = false;
                }
                else if(!(p1 < p2 && p2 < p3))ok = false;
            }
        }

        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 200005
#define INF (1<<30)
using namespace std;

vector<int>L[N];
pair<int, int> T[N];
int ans[N], in[N], Q[N];

int main(){

    int n, m;
    while(cin>>n>>m){

        T[m].first = INF;
        int nodes = m, u, v;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){

                scanf("%d", &T[j].first);
                T[j].second = j;
            }

            sort(T, T + m);
            for(int j = m - 1; j >= 0; j--){

                if(T[j].first < 0)break;
                if(T[j].first != T[j + 1].first){

                    u = nodes;
                    for(int l = j + 1; l < m; l++){

                        v = T[l].second;
                        in[v]++;

                        L[u].pb(v);
                        if(T[l].first != T[l + 1].first)break;
                    }
                    nodes++;
                }

                u = T[j].second;
                v = nodes - 1;

                in[v]++;
                L[u].pb(v);
            }
        }

        int head = 0, tail = 0, ct = 0, top = 0;

        for(int i = 0; i < nodes; i++)
            if(in[i] == 0)Q[tail++] = i;

        while(head < tail){

            int u = Q[head++]; ct++;
            if(u < m)ans[top++] = u;

            for(int i = 0; i < L[u].size(); i++){

                int v = L[u][i];
                in[v]--;
                if(in[v] == 0)Q[tail++] = v;
            }
        }

        if(ct != nodes)puts("-1");
        else{

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", ans[i] + 1);
            }
            puts("");
        }
    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 1000005

using namespace std;

vector<int>v[N];
int n, m;

bool menor(int x, int y){

    int c1 = 0, c2 = 0;
    for(int i = 0; i < n; i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[x][i] < v[y][i])c1++;
        else if(v[y][i] < v[x][i])c2++;
    }

    if(c1 == 0 && c2 == 0)return true;
    if(c1 > 0 && c2 > 0)return false;
    return c1 > 0;
}

int p[N];

int main(){

    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        sort(p, p + m, menor);

        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 1; j < m; j++){

                int p1 = -(1<<30);
                int p2 = v[p[j]][i];;
                int p3 = (1<<30) + 2;

                if(v[p[j - 1]][i] >= 0)p1 = v[p[j - 1]][i];
                if(j + 1 < m && v[p[j + 1]][i] >= 0)p3 = v[p[j + 1]][i];
                //cout << p1 << " " << p2 << " " << p3 << endl;
                if(p2 == -1){

                    if(!(p1 <= p3))ok = false;
                }
                else if(!(p1 <= p2 && p2 <= p3))ok = false;
            }
        }

        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 1000005

using namespace std;

vector<int>v[N];
int n, m;

bool menor(int x, int y){

    int c1 = 0, c2 = 0;
    for(int i = 0; i < n; i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[x][i] < v[y][i])c1++;
        else if(v[y][i] < v[x][i])c2++;
    }

    if(c1 == 0 && c2 == 0)return true;
    if(!(c1 == 0) && !(c2 == 0))return false;
    return c2 == 0;
}

int p[N];

int main(){

    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        sort(p, p + m, menor);

        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 1; j < m; j++){

                int p1 = -(1<<30);
                int p2 = v[p[j]][i];;
                int p3 = (1<<30) + 2;

                if(v[p[j - 1]][i] >= 0)p1 = v[p[j - 1]][i];
                if(j + 1 < m && v[p[j + 1]][i] >= 0)p3 = v[p[j + 1]][i];
                //cout << p1 << " " << p2 << " " << p3 << endl;
                if(p2 == -1){

                    if(!(p1 <= p3))ok = false;
                }
                else if(!(p1 <= p2 && p2 <= p3))ok = false;
            }
        }

        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 1000005

using namespace std;

vector<int>v[N];
int n, m;

bool menor(int x, int y){

    for(int i = 0; i < n; i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[y][i] < v[x][i])return false;
    }

    return true;
}

int p[N];

int main(){

    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        //sort(p, p + m, menor);

        for(int i = 0; i < m; i++){
            for(int j = i + 1; j < m; j++){

                if(!menor(p[i], p[j]))swap(p[i], p[j]);
            }
        }

        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 1; j < m; j++){

                int p1 = -(1<<30);
                int p2 = v[p[j]][i];;
                int p3 = (1<<30) + 2;

                if(v[p[j - 1]][i] >= 0)p1 = v[p[j - 1]][i];
                if(j + 1 < m && v[p[j + 1]][i] >= 0)p3 = v[p[j + 1]][i];
                //cout << p1 << " " << p2 << " " << p3 << endl;
                if(p2 == -1){

                    if(!(p1 <= p3))ok = false;
                }
                else if(!(p1 <= p2 && p2 <= p3))ok = false;
            }
        }

        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 100005

using namespace std;

vector<int>v[N];

bool menor(int x, int y){

    int c1 = 0, c2 = 0;
    for(int i = 0; i < v[x].size(); i++){

        if(v[x][i] == -1 || v[y][i] == -1)continue;
        if(v[x][i] < v[y][i])c1++;
        else if(v[y][i] < v[x][i])c2++;
    }

    if(c1 == 0 && c2 == 0)return true;
    if(c1 > 0 && c2 > 0)return false;
    return c1 > 0;
}

int p[N];

int main(){

    int n, m;
    while(cin>>n>>m){

        for(int i = 0; i < m; i++)v[i].resize(n);

        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                scanf("%d", &v[j][i]);

        for(int i = 0; i < m; i++)p[i] = i;
        sort(p, p + m, menor);

        bool ok = true;
        for(int i = 1; i < m && ok; i++)if(!menor(p[i - 1], p[i]))ok = false;
        if(ok){

            for(int i = 0; i < m; i++){

                if(i)printf(" ");
                printf("%d", p[i] + 1);
            }
        }
        else puts("-1");

    }

}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 200000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,t[maxn];
vector <int> v[maxn],f;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
	mark[x] = 1;
	for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
	f.pb(x);
}
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if(m == 1) { cout << 1 << endl; return 0; }
	for(int i = 1 ; i <= n ; i++) {
				p.clear();
				p.pb(pii(0,0));
				for(int j = 1 ; j <= m ; j++) {
					int x;
					cin >> x;
					p.pb(pii(x,j));
				}
				sort(p.begin()+1,p.end());
				int j = 1;
				while(p[j].X == -1) j++;
				for(; j < int(p.size()) ; j++) {
					int st = j;
					int fn = j;
					while(fn < int(p.size())-1 && p[st].X == p[fn+1].X) fn++;
					if(fn+1 != int(p.size()))
						for(int l = st ; l <= fn ; l++) v[p[l].Y].pb(fn+m);
					if(st > 1)
						for(int l = st ; l <= fn ; l++) v[st-1+m].pb(p[l].Y);
				}
	}
	for(int i = 1 ; i <= 2*m ; i++) {
		sort(v[i].begin(),v[i].end());
	//	cout << i << "**********\n";
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	//	for(int j = 0 ; j < v[i].size() ; j++) cout << v[i][j] << ' '; cout << endl;
	}
	for(int i = 1 ; i <= 2*m ; i++) if(!mark[i]) dfs(i);
	for(int i = f.size()-1 ; i >= 0 ; i--) t[f[i]] = (2*m)-i;
	for(int i = 1 ; i <= m ; i++) {
		for(int j = 0 ; j < v[i].size() ; j++)
			if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
	}
	for(int i = f.size()-1 ; i >= 0 ; i--) if(f[i] <= m) cout << f[i] << ' '; cout << endl;
	return 0;
}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 200000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,t[maxn];
vector <int> v[maxn],f;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
	mark[x] = 1;
	for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
	f.pb(x);
}
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if(m == 1) { cout << 1 << endl; return 0; }
	for(int i = 1 ; i <= n ; i++) {
				p.clear();
				p.pb(pii(0,0));
				for(int j = 1 ; j <= m ; j++) {
					int x;
					cin >> x;
					p.pb(pii(x,j));
				}
				sort(p.begin()+1,p.end());
				int j = 1;
				while(p[j].X == -1) j++;
				for(; j < int(p.size()) ; j++) {
					int st = j;
					int fn = j;
					while(fn < int(p.size())-1 && p[st].X == p[fn+1].X) fn++;
					if(fn+1 != int(p.size()))
						for(int l = st ; l <= fn ; l++) v[p[l].Y].pb(fn+m);
					if(st > 1)
						for(int l = st ; l <= fn ; l++) v[st-1+m].pb(p[l].Y);
				}
	}
	for(int i = 1 ; i <= 2*m-1 ; i++) {
		sort(v[i].begin(),v[i].end());
	//	cout << i << "**********\n";
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	//	for(int j = 0 ; j < v[i].size() ; j++) cout << v[i][j] << ' '; cout << endl;
	}
	for(int i = 1 ; i <= 2*m ; i++) if(!mark[i]) dfs(i);
	for(int i = f.size()-1 ; i >= 0 ; i--) t[f[i]] = (2*m)-i;
	for(int i = 1 ; i <= 2*m ; i++) {
		for(int j = 0 ; j < v[i].size() ; j++)
			if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
	}
	for(int i = f.size()-1 ; i >= 0 ; i--) if(f[i] <= m) cout << f[i] << ' '; cout << endl;
	return 0;
}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 100000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,c,t[maxn];
vector <int> v[maxn],fn;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
	mark[x] = c;
	for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
	fn.pb(x);
}
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if(m == 1) { cout << 1 << endl; return 0; }
	for(int i = 1 ; i <= n ; i++) {
				p.clear();
				for(int j = 1 ; j <= m ; j++) {
					int x;
					cin >> x;
					if(x != -1) p.pb(pii(x,j));
				}
				sort(p.begin(),p.end());
				for(int j = 0 ; j < int(p.size())-1 ; j++) {
					if(p[j].X < p[j+1].X) {
						v[p[j].Y].pb(p[j+1].Y);
						int y = j-1;
						while(y >= 0 && p[y].X == p[j].X) { v[p[y].Y].pb(p[j+1].Y); y--; }
					}
				}
				for(int j = int(p.size())-1 ; j > 0 ; j--) {
					if(p[j].X > p[j-1].X) {
						int y = j+1;
						while(y < p.size() && p[y].X == p[j].X) { v[p[j-1].Y].pb(p[y].Y); y++; }
					}
				}
	}
	for(int i = 1 ; i <= m ; i++) {
		sort(v[i].begin(),v[i].end());
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	}
	for(int i = 1 ; i <= m ; i++) if(!mark[i]) { c++; dfs(i); }
	for(int i = fn.size()-1 ; i >= 0 ; i--) t[fn[i]] = n-i;
	for(int i = 1 ; i <= m ; i++) {
		for(int j = 0 ; j < v[i].size() ; j++)
			if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
	}
	for(int i = fn.size()-1 ; i >= 0 ; i--) cout << fn[i] << ' '; cout << endl;

	return 0;
}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 100000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,c,t[maxn];
vector <int> v[maxn],fn;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
	mark[x] = c;
	for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
	fn.pb(x);
}
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i++) {
				p.clear();
				for(int j = 1 ; j <= m ; j++) {
					int x;
					cin >> x;
					if(x != -1) p.pb(pii(x,j));
				}
				sort(p.begin(),p.end());
				for(int j = 0 ; j < p.size()-1 ; j++)
					if(p[j].X < p[j+1].X) {
						v[p[j].Y].pb(p[j+1].Y);
						int y = j-1;
						while(y >= 0 && p[y].X == p[j].X) { v[p[y].Y].pb(p[j+1].Y); y--; }
					}
				for(int j = p.size()-1 ; j > 0 ; j--)
					if(p[j].X > p[j-1].X) {
						int y = j+1;
						while(y < p.size() && p[y].X == p[j].X) { v[p[j-1].Y].pb(p[y].Y); y++; }
					}
	}
	for(int i = 1 ; i <= m ; i++) {
		sort(v[i].begin(),v[i].end());
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	}
	for(int i = 1 ; i <= m ; i++) if(!mark[i]) { c++; dfs(i); }
	for(int i = fn.size()-1 ; i >= 0 ; i--) t[fn[i]] = n-i;
	for(int i = 1 ; i <= m ; i++) {
		for(int j = 0 ; j < v[i].size() ; j++)
			if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
	}
	for(int i = fn.size()-1 ; i >= 0 ; i--) cout << fn[i] << ' '; cout << endl;

	return 0;
}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 100000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,c,t[maxn];
vector <int> v[maxn],fn;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
	mark[x] = c;
	for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
	fn.pb(x);
}
int main () {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if(m == 1) { cout << 1 << endl; return 0; }
	for(int i = 1 ; i <= n ; i++) {
				p.clear();
				for(int j = 1 ; j <= m ; j++) {
					int x;
					cin >> x;
					if(x != -1) p.pb(pii(x,j));
				}
				sort(p.begin(),p.end());
				for(int j = 0 ; j < int(p.size())-1 ; j++) {
					if(p[j].X < p[j+1].X) {
						v[p[j].Y].pb(p[j+1].Y);
						int y = j-1;
						while(y >= 0 && p[y].X == p[j].X) { v[p[y].Y].pb(p[j+1].Y); y--; }
					}
				}
				for(int j = int(p.size())-1 ; j > 0 ; j--) {
					if(p[j].X > p[j-1].X) {
						int y = j+1;
						while(y < p.size() && p[y].X == p[j].X) { v[p[j-1].Y].pb(p[y].Y); y++; }
					}
				}
	}
	for(int i = 1 ; i <= m ; i++) {
		sort(v[i].begin(),v[i].end());
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	}
	for(int i = 1 ; i <= m ; i++) if(!mark[i]) { c++; dfs(i); }
	for(int i = fn.size()-1 ; i >= 0 ; i--) t[fn[i]] = m-i;
	for(int i = 1 ; i <= m ; i++) {
		for(int j = 0 ; j < v[i].size() ; j++)
			if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
	}
	for(int i = fn.size()-1 ; i >= 0 ; i--) cout << fn[i] << ' '; cout << endl;

	return 0;
}


/*
PROG:
LANG:
*/
// User: al13pn
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <utility>
#include <list>
#include <cstdlib>
#include <ctime>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define X first
#define Y second
//#define X real()
//#define Y imag()
#define mp make_pair
#define sqr(x) ((((x)*(x))))
#define pb push_back
#define eps 0.000001
using namespace std;
typedef complex<long double> point;
typedef long double ld;
typedef long long ll;
const int mod = 1000*1000*1000+7;
const int maxn = 200000+10;
const int inf = 1000000000;
ifstream fin("relay.in");
ofstream fout("relay.out");
int n,m,t[maxn],now,prv;
vector <int> v[maxn],f;
vector <pii> p;
int mark[maxn],o;
void dfs(int x) {
    mark[x] = 1;
    for(int i = 0 ; i < v[x].size() ; i++) if(!mark[v[x][i]]) dfs(v[x][i]);
    f.pb(x);
}
int main () {
    ios::sync_with_stdio(false);
    cin >> n >> m; now = m+1;
    if(m == 1) { cout << 1 << endl; return 0; }
    for(int i = 1 ; i <= n ; i++) {
                p.clear();
                p.pb(pii(0,0));
                for(int j = 1 ; j <= m ; j++) {
                    int x;
                    cin >> x;
                    p.pb(pii(x,j));
                }
                sort(p.begin()+1,p.end());
                int j = 1;
                while(p[j].X == -1) j++;
                int u = j;
                for(; j < int(p.size()) ; j++) {
                    int st = j;
                    int fn = j;
                    while(fn < int(p.size())-1 && p[st].X == p[fn+1].X) fn++;
                    if(fn+1 != int(p.size()))
                        for(int l = st ; l <= fn ; l++) v[p[l].Y].pb(now);
                    if(st > u)
                        for(int l = st ; l <= fn ; l++) v[prv].pb(p[l].Y);
                    prv = now;
                    now++;
                    j = fn;
                }
    }
    for(int i = 1 ; i <= now ; i++) {
        sort(v[i].begin(),v[i].end());
    //  cout << i << "**********\n";
        v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
    //  for(int j = 0 ; j < v[i].size() ; j++) cout << v[i][j] << ' '; cout << endl;
    }
    for(int i = 1 ; i <= now ; i++) if(!mark[i]) dfs(i);
    for(int i = f.size()-1 ; i >= 0 ; i--) { t[f[i]] = (2*m)-i; }
    for(int i = 1 ; i <= now ; i++) {
        for(int j = 0 ; j < v[i].size() ; j++)
            if(t[i] > t[v[i][j]]) { cout << -1 << endl; return 0; }
    }
    for(int i = f.size()-1 ; i >= 0 ; i--) if(f[i] <= m) cout << f[i] << ' '; cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn=100007;

int n,m,**arr,id[maxn];
bool check;

bool cmp(const int &a, const int &b){
    if(!check) return 1;
    int val=0;
    FOR(i,1,n)
        if(arr[i][id[a]]!=-1 && arr[i][id[b]]!=-1){
            if(arr[i][id[a]]<arr[i][id[b]]){
                if(val==-1){
                    check=0;
                    return 1;
                }
                val=1;
            }else if(arr[i][id[a]]>arr[i][id[b]]){
                if(val==1){
                    check=0;
                    return 1;
                }
                val=-1;
            }
        }
    return val==1;
}

int main(){
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    arr=new int*[n+1];
    FOR(i,1,n) arr[i]=new int[m+1];
    FOR(i,1,n) FOR(j,1,m) scanf("%d",&arr[i][j]);
    FOR(i,1,m) id[i]=i;
    check=1;
    sort(id+1,id+m+1,cmp);
    int v;
    FOR(i,1,n){
        if(!check) break;
        v=0;
        FOR(j,1,m) if(arr[i][id[j]]!=-1){
            if(arr[i][id[j]]<v){
                check=0;
                break;
            }
            v=arr[i][id[j]];
        }
    }
    if(check) FOR(i,1,m) printf("%d ",id[i]);
    else puts("-1");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn=100007;

int n,m,cnt,ans[maxn*2];
struct node{int v,id;} list[maxn];
vector<int> a[maxn*2];
bool indfs[maxn*2],free1[maxn*2],found_cycle;

bool cmp(const node &a, const node &b){
    return a.v<b.v;
}

void dfs(int u){
    if(found_cycle) return;
    int v;
    free1[u]=0;
    indfs[u]=1;
    REP(i,sz(a[u])){
        v=a[u][i];
        if(free1[v]) dfs(v);
        else if(indfs[v]){
            found_cycle=1;
            return;
        }
    }
    ans[cnt--]=u;
    indfs[u]=0;
}

int main(){
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int v,x,y,N=m+1,z;
    REP(j,n){
        cnt=0;
        FOR(i,1,m){
            scanf("%d",&v);
            if(v==-1) continue;
            list[++cnt].v=v;
            list[cnt].id=i;
        }
        sort(list+1,list+cnt+1,cmp);
        x=1; z=m+1;
        while(x<=cnt){
            y=x;
            while(y<cnt && list[y+1].v==list[x].v) y++;
            FOR(it,x,y) a[z].pb(list[it].id);
            z=++N;
            FOR(it,x,y) a[list[it].id].pb(z);
            x=y+1;
        }
    }
    reset(free1,1); reset(indfs,0);
    cnt=N; found_cycle=0;
    FOR(i,1,N) if(free1[i]) dfs(i);

    if(found_cycle) puts("-1");
    else
        FOR(i,1,N) if(ans[i]<=m) printf("%d ",ans[i]);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn=100007;

int n,m,cnt,ans[maxn*2];
struct node{int v,id;} list[maxn];
vector<int> a[maxn*2];
bool indfs[maxn*2],free1[maxn*2],found_cycle;

bool cmp(const node &a, const node &b){
    return a.v<b.v;
}

void dfs(int u){
    if(found_cycle) return;
    int v;
    free1[u]=0;
    indfs[u]=1;
    REP(i,sz(a[u])){
        v=a[u][i];
        if(free1[v]) dfs(v);
        else if(indfs[v]){
            found_cycle=1;
            return;
        }
    }
    ans[cnt--]=u;
    indfs[u]=0;
}

int main(){
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int v,x,y,N=m+1,z;
    REP(j,n){
        cnt=0;
        FOR(i,1,m){
            scanf("%d",&v);
            if(v==-1) continue;
            list[++cnt].v=v;
            list[cnt].id=i;
        }
        sort(list+1,list+cnt+1,cmp);
        x=1; z=m+1;
        while(x<=cnt){
            y=x;
            while(y<cnt && list[y+1].v==list[x].v) y++;
            FOR(it,x,y) a[z].pb(list[it].id);
            if(y<n){
                z=++N;
                FOR(it,x,y) a[list[it].id].pb(z);
            }
            x=y+1;
        }
    }
    reset(free1,1); reset(indfs,0);
    cnt=N; found_cycle=0;
    FOR(i,1,N) if(free1[i]) dfs(i);

    if(found_cycle) puts("-1");
    else
        FOR(i,1,N) if(ans[i]<=m) printf("%d ",ans[i]);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn=100007;

int n,m,cnt,ans[maxn*2];
struct node{int v,id;} list[maxn];
vector<int> a[maxn*2];
bool indfs[maxn*2],free1[maxn*2],found_cycle;

bool cmp(const node &a, const node &b){
    return a.v<b.v;
}

void dfs(int u){
    if(found_cycle) return;
    int v;
    free1[u]=0;
    indfs[u]=1;
    REP(i,sz(a[u])){
        v=a[u][i];
        if(free1[v]) dfs(v);
        else if(indfs[v]){
            found_cycle=1;
            return;
        }
    }
    ans[cnt--]=u;
    indfs[u]=0;
}

int main(){
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int v,x,y,N=n+1,z;
    REP(j,n){
        cnt=0;
        FOR(i,1,m){
            scanf("%d",&v);
            if(v==-1) continue;
            list[++cnt].v=v;
            list[cnt].id=i;
        }
        sort(list+1,list+cnt+1,cmp);
        x=1; z=n+1;
        while(x<=cnt){
            y=x;
            while(y<cnt && list[y+1].v==list[x].v) y++;
            FOR(it,x,y) a[z].pb(list[it].id);
            z=++N;
            FOR(it,x,y) a[list[it].id].pb(z);
            x=y+1;
        }
    }
    reset(free1,1); reset(indfs,0);
    cnt=N; found_cycle=0;
    FOR(i,1,N) if(free1[i]) dfs(i);

    if(found_cycle) puts("-1");
    else
        FOR(i,1,N) if(ans[i]<=n) printf("%d ",ans[i]);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 1e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
int b[maxn];
int c[maxn];
int n, m;

bool cmp(int v, int u){
//     epr("v %d u %d ", v, u);
    for(int i = 0; i < n; i++)
        if (a[i][v] != -1 && a[i][u] != -1 && a[i][v] > a[i][u]){
//             epr("   0\sn");
            return 0;
        }
//     epr("
    return 1;
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for(int i = 0; i < m; i++)
        b[i] = i;
//     epr("1\n");
    sort(b, b + m, cmp);
//     epr("2\n");
    for(int j = 0; j < m - 1; j++)
        for(int i = 0; i < n; i++)
            if (a[i][b[j]] != -1){
    if (a[i][b[j]] < c[j]){
        cout << "-1\n";
        return 0;
    }
    c[j] = max(c[i], a[i][b[j]]);
            }
    for(int i = 0; i < m; i++)
        printf("%d ", b[i] + 1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 2e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
int b[maxn];
int b1[maxn];
int c[maxn];
int n, m;

bool cmp(int v, int u){
//     epr("v %d u %d ", v, u);
    for(int i = 0; i < n; i++)
        if (a[i][v] != -1 && a[i][u] != -1 && a[i][v] >= a[i][u]){
//             epr("   0\sn");
            return 0;
        }
//     epr("
    return 1;
}

void mergesort(int l, int r){
    if (r - l <= 1) return;
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for(int i = 0; i < m; i++)
        b[i] = i;
//     epr("1\n");
//     qsort(0, m - 1);
    stable_sort(b, b + m, cmp);
//     epr("2\n");
    for(int j = 0; j < m; j++)
        for(int i = 0; i < n; i++)
            if (a[i][b[j]] != -1){
    if (a[i][b[j]] < c[i]){
        cout << "-1\n";
        return 0;
    }
    c[i] = max(c[i], a[i][b[j]]);
            }
    for(int i = 0; i < m; i++)
        printf("%d ", b[i] + 1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 2e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
pair < int, int > b[maxn];
vector < int > e[maxn];
vector < int > ans;
int use[maxn];

void dfs(int v){
    use[v] = 1;
    for(int i = 0; i < (int)e[v].size(); i++){
        if (use[e[v][i]] == 1){
            printf("-1\n");
            exit(0);
        }
        if (use[e[v][i]] == 0)
            dfs(e[v][i]);
    }
    use[v] = 2;
    ans.pb(v);
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    int n, m, uk, p;
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for(int i = 0; i < n; i++){
        uk = 0;
        for(int j = 0; j < m; j++)
            if (a[i][j] != -1)
    b[uk++] = mp(a[i][j], j);
        sort(b, b + uk);
        p = -1;
//         epr("%d uk\n", uk);
        for(int j = 0; j < uk; j++){
            if (p != -1) e[b[p].ss].pb(b[j].ss);
            if (j + 1 != uk && b[j + 1].ff > b[j].ff) p = j;
        }
        p = -1;
        for(int j = uk - 1; j >= 0; j--){
            if (p != -1) e[b[j].ss].pb(b[p].ss);
            if (j != 0 && b[j - 1].ff < b[j].ff) p = j;
        }
    }/*
    for(int i = 0; i < m; i++){
        epr("%d:   ", i);
        for(int j = 0; j < (int)e[i].size(); j++)
            epr("%d ", e[i][j]);
        epr("\n");

    }*/
    for(int i = 0; i < m; i++)
        if (use[i] == 0)
            dfs(i);
    for(int i = (int)ans.size() - 1; i >= 0; i--)
        printf("%d ", ans[i] + 1);
    printf("\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 2e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
int b[maxn];
int c[maxn];
int n, m;

bool cmp(int v, int u){
//     epr("v %d u %d ", v, u);
    for(int i = 0; i < n; i++)
        if (a[i][v] != -1 && a[i][u] != -1 && a[i][v] > a[i][u]){
//             epr("   0\sn");
            return 0;
        }
//     epr("
    return 1;
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for(int i = 0; i < m; i++)
        b[i] = i;
//     epr("1\n");
//     qsort(0, m - 1);
    stable_sort(b, b + m, cmp);
//     epr("2\n");
    for(int j = 0; j < m; j++)
        for(int i = 0; i < n; i++)
            if (a[i][b[j]] != -1){
    if (a[i][b[j]] < c[i]){
        cout << "-1\n";
        return 0;
    }
    c[i] = max(c[i], a[i][b[j]]);
            }
    for(int i = 0; i < m; i++)
        printf("%d ", b[i] + 1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 2e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
vector < int > e[maxn];
pair < int, int > b[maxn];
vector < int > ans;
int use[maxn];

void dfs(int v){
    use[v] = 1;
    for(int i = 0; i < (int)e[v].size(); i++){
        if (use[e[v][i]] == 1){
            cout << "-1\n";
            exit(0);
        }
        if (use[e[v][i]] == 0)
            dfs(e[v][i]);
    }
    ans.pb(v);
    use[v] = 2;
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    int n, m, uk, free, l, p;
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    free = m;
    for(int i = 0; i < n; i++){
        uk = 0;
        for(int j = 0; j < m; j++)
            if (a[i][j] != -1)
    b[uk++] = mp(a[i][j], j);
        sort(b, b + uk);
        l = 0;
        p = -1;
        for(int j = 0; j < uk; j++){
            if (p != -1) e[p].pb(b[j].ss);
            if (j + 1 != uk && b[j + 1].ff > b[j].ff){
    p = free++;
    for(int k = l; k < j + 1; k++)
        e[b[k].ss].pb(p);
    l = j + 1;
            }
        }
    }
//     for(int i = 0; i < free; i++){
//         epr("%d :   ", i);
//         for(int j = 0; j < (int)e[i].size(); j++)
//             epr("%d ", e[i][j]);
//         epr("\n");
//     }
//     epr("free %d\n", free);
    for(int i = 0; i < free; i++)
        if (use[i] == 0)
            dfs(i);
  /*  for(int i = 0; i < (int)ans.size(); i++)
        epr("%d ", ans[i]);
    epr("\n\n\n");
  */
    for(int i = (int)ans.size() - 1; i >= 0; i--)
        if (ans[i] < m)
            printf("%d ", ans[i] + 1);
    printf("\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cassert>
#include <ctime>
#include <queue>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#ifdef DEBUG
    #define epr(...) fprintf(stderr, __VA_ARGS__)
#else
    #define epr
#endif

const int maxn = 2e5 + 10;
const int inf = (int)1e9;

vector < vector < int > > a;
int b[maxn];
int c[maxn];
int n, m;

bool cmp(int v, int u){
//     epr("v %d u %d ", v, u);
    for(int i = 0; i < n; i++)
        if (a[i][v] != -1 && a[i][u] != -1 && a[i][v] > a[i][u]){
//             epr("   0\sn");
            return 0;
        }
//     epr("
    return 1;
}

int main(){
//     freopen("in", "r", stdin);
//     freopen("out", "w", stdout);
    scanf("%d%d", &n, &m);
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(m);
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for(int i = 0; i < m; i++)
        b[i] = i;
//     epr("1\n");
    sort(b, b + m, cmp);
//     epr("2\n");
    for(int j = 0; j < m; j++)
        for(int i = 0; i < n; i++)
            if (a[i][b[j]] != -1){
    if (a[i][b[j]] < c[i]){
        cout << "-1\n";
        return 0;
    }
    c[i] = max(c[i], a[i][b[j]]);
            }
    for(int i = 0; i < m; i++)
        printf("%d ", b[i] + 1);
    printf("\n");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#define N 100005
using namespace std;
set<pair<int,int> > smallest[N];
set<pair<int,int> > small;
vector<vector<int> > a;
vector<int> ans;
int bad[N];

void update(__typeof(smallest[0].begin()) iter){
    small.erase(make_pair(bad[iter->second], iter->second));
    bad[iter->second]--;
    small.insert(make_pair(bad[iter->second], iter->second));
}

int main(){
    int n, m, i, j, x, u;
    scanf("%d%d",&n,&m);
    a.resize(m);
    for(i=0;i<n;i++)
        for(j=0;j<m;j++){
            scanf("%d",&x);
            a[j].push_back(x);
            if(x!=-1)
                smallest[i].insert(make_pair(x,j));
        }
    for(j=0;j<m;j++)
        for(i=0;i<n;i++)
            if(a[j][i]!=-1 && a[j][i]!=smallest[i].begin()->first)
                bad[j]++;
    for(j=0;j<m;j++)
        small.insert(make_pair(bad[j],j));

    for(i=0;i<m;i++){
        if(small.begin()->first != 0) break;
        ans.push_back(small.begin()->second+1);
        u = small.begin()->second;
        small.erase(small.begin());
        for(j=0;j<n;j++)
            if(a[u][j]!=-1){
                int tmp = a[u][j];
                smallest[j].erase(make_pair(a[u][j],u));
                if(smallest[j].empty()) continue;
                if(smallest[j].begin()->first!=tmp)
                for(__typeof(smallest[j].begin()) iter=smallest[j].begin();iter!=smallest[j].end();iter++)
                if(iter->first == smallest[j].begin()->first)
                update(iter);
            }
    }

    if(i!=m) puts("-1");else {
        for(i=0;i<m;i++)
        printf("%d%s",ans[i],i==m-1?"\n":" ");
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

queue<int> q;

int ff = 0, m, n;
int ru[100005];
vector<vector<int> > a;
vector<int> vec[100005];
vector<int> ans;

int main(){
    int i, j, x, p, f, f1;
    scanf("%d%d",&n,&m);
    a.resize(n);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&x);
            a[i].push_back(x);
        }
    }
    for(i=0;i<m;i++)
    for(j=i+1;j<m;j++){
        f = 0;
        for(p=0;p<n;p++){
            if(a[p][i]!=-1 && a[p][j]!=-1 && a[p][i]!=a[p][j]){
                f1 = (a[p][i]<a[p][j])+1;
                if(f==0) f=f1;else
                if(f1!=f) ff = 1;
            }
        }
        if(f==2) {vec[i].push_back(j);ru[j]++;}else
        if(f==1) {vec[j].push_back(i);ru[i]++;}
    }
    if(ff){puts("-1");return 0;}

    for(i=0;i<m;i++)
        if(ru[i]==0)
        q.push(i);
    while(!q.empty()){
        int u = q.front();
        ans.push_back(u+1);
        q.pop();
        for(i=0;i<vec[u].size();i++){
            ru[vec[u][i]]--;
            if (ru[vec[u][i]] ==0) q.push(vec[u][i]);
        }
    }
    for(i=0;i<ans.size();i++)
        i==ans.size()-1?printf("%d\n",ans[i]):printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int ff = 0, m, n;

struct Pt{
    vector<int> vec;
    int id;
    bool operator < (Pt o) const{
        int i, f1, f = 0;
        if(ff) return false;
        for(i=0;i<n;i++)
        if(vec[i]!=-1 && o.vec[i]!=-1 && vec[i]!=o.vec[i]){
            f1 = (vec[i]<o.vec[i]) + 1;
            if(f==0)f=f1;else
            if(f!=f1) ff = 1;
        }
        return f-1;
    }
} el[100005];

int main(){
    int j, x, i;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&x);
            el[j].vec.push_back(x);
        }
    }
    for(j=0;j<m;j++)
        el[j].id = j+1;
    sort(el,el+m);
    if(ff) puts("-1");else
    for(i=0;i<m;i++)
        i==m-1?printf("%d\n",el[i].id):printf("%d ",el[i].id);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int ff = 0, m, n;

struct Pt{
    vector<int> vec;
    int id;
    bool operator < (Pt o) const{
        int i, f1, f = 0;
        if(ff) return false;
        for(i=0;i<n;i++)
        if(vec[i]!=-1 && o.vec[i]!=-1 && vec[i]!=o.vec[i]){
            f1 = (vec[i]<o.vec[i]) + 1;
            if(f==0)f=f1;else
            if(f!=f1) ff = 1;
        }
        return f==0?f:f-1;
    }
} el[100005];

int main(){
    int j, x, i;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&x);
            el[j].vec.push_back(x);
        }
    }
    for(j=0;j<m;j++)
        el[j].id = j+1;
    sort(el,el+m);
    if(ff) puts("-1");else
    for(i=0;i<m;i++)
        i==m-1?printf("%d\n",el[i].id):printf("%d ",el[i].id);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define Size(x) (int)(x.size())
#define rep(i, n) for(int i=0; i<n; ++i)
#define F first
#define S second

const int MAXn = 100*1000 + 5;

typedef pair<int, int> pii;

int n, m;
vector<int> ar[MAXn], v;
vector<int> adj[MAXn], adjr[MAXn];
int num;
pii b[MAXn];
bool mark[MAXn*3];

void DFSt(int x)
{
	mark[x] = 1;
	rep(i, Size(adj[x]))
		if(!mark[adj[x][i]])
			DFSt(adj[x][i]);
	v.push_back(x);
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	rep(i, n) {
		ar[i].resize(m);
		rep(j, m)
			cin >> ar[i][j];
	}

	num = m;

	rep(i, n) {
		rep(j, m)
			b[j] = pii(ar[i][j], j);
		sort(b, b+m);
		int j = 0;
		while(j<m)
			if(b[j].F==-1)
				++j;
			else {
				int k = j+1;
				while(k<m && b[j].F==b[k].F) ++k;
				if(k==m) break;
				int p = k+1;
				while(p<m && b[k].F==b[p].F) ++p;
				for(int x=j; x<k; ++x) {
					adj[b[x].S].push_back(num);
					adjr[num].push_back(b[x].S);
				}
				for(int x=k; x<p; ++x) {
					adj[num].push_back(b[x].S);
					adjr[b[x].S].push_back(num);
				}
				j = k;
				++num;
			}
	}

	rep(i, num)
		if(!mark[i])
			DFSt(i);

	fill_n(mark, num, 0);
	for(int i=num-1; i>=0; --i) {
		int x = v[i];
		mark[x] = 1;
		rep(j, Size(adjr[x]))
			if(!mark[adjr[x][j]]) {
				cout << -1 << endl;
				return 0;
			}
	}

	for(int i=num-1; i>=0; --i) if(v[i]<m)
		cout << v[i]+1 << ' ';
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i, n) for(int i=0; i<n; ++i)

const int MAXn = 100*1000 + 5;

int n, m;
vector<int> ar[MAXn];
int b[MAXn];

bool cmp(int a, int b)
{
	rep(i, n)
		if(ar[i][a] != -1 && ar[i][b]!=-1 && ar[i][a]!=ar[i][b])
			return ar[i][a] < ar[i][b];
	return false;
}

bool check(int a, int b)
{
	rep(i, n)
		if(ar[i][a]!=-1 && ar[i][b]!=-1 && ar[i][a]>ar[i][b])
			return false;
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	rep(i, n) {
		ar[i].resize(m);
		rep(j, m)
			cin >> ar[i][j];
	}

	rep(i, m)
		b[i] = i;
	sort(b, b+m, cmp);

	rep(i, m-1)
		if(!check(b[i], b[i+1])) {
			cout << -1 << endl;
			return 0;
		}
	rep(i, m)
		cout << b[i]+1 << ' ';
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define Size(x) (int)(x.size())
#define rep(i, n) for(int i=0; i<n; ++i)
#define F first
#define S second

const int MAXn = 100*1000 + 5;

typedef pair<int, int> pii;

int n, m;
vector<int> ar[MAXn], v;
vector<int> adj[MAXn], adjr[MAXn];
pii b[MAXn];
bool mark[MAXn];

void DFSt(int x)
{
	mark[x] = 1;
	rep(i, Size(adj[x]))
		if(!mark[adj[x][i]])
			DFSt(adj[x][i]);
	v.push_back(x);
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	rep(i, n) {
		ar[i].resize(m);
		rep(j, m)
			cin >> ar[i][j];
	}

	rep(i, n) {
		rep(j, m)
			b[j] = pii(ar[i][j], j);
		sort(b, b+m);
		rep(j, m)
			if(b[j].F!=-1) {
				int k = j+1;
				while(k<m && b[j].F==b[k].F) ++k;
				if(k!=m) {
					for(; j<k; ++j) {
						adj[b[j].S].push_back(b[k].S);
						adjr[b[k].S].push_back(b[j].S);
					}
				}
				j = k-1;
			}
	}

	rep(i, m)
		if(!mark[i])
			DFSt(i);

	fill_n(mark, m, 0);
	for(int i=m-1; i>=0; --i) {
		int x = v[i];
		mark[x] = 1;
		rep(j, Size(adjr[x]))
			if(!mark[adjr[x][j]]) {
				cout << -1 << endl;
				return 0;
			}
	}

	for(int i=m-1; i>=0; --i)
		cout << v[i]+1 << ' ';
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define Size(x) (int)(x.size())
#define rep(i, n) for(int i=0; i<n; ++i)
#define F first
#define S second

const int MAXn = 100*1000 + 5;

typedef pair<int, int> pii;

int n, m;
vector<int> ar[MAXn], v;
vector<int> adj[MAXn], adjr[MAXn];
pii b[MAXn];
bool mark[MAXn];

void DFSt(int x)
{
	mark[x] = 1;
	rep(i, Size(adj[x]))
		if(!mark[adj[x][i]])
			DFSt(adj[x][i]);
	v.push_back(x);
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	rep(i, n) {
		ar[i].resize(m);
		rep(j, m)
			cin >> ar[i][j];
	}

	rep(i, n) {
		rep(j, m)
			b[j] = pii(ar[i][j], j);
		sort(b, b+m);
		rep(j, m)
			if(b[j].F!=-1) {
				int k = j+1;
				while(k<m && b[j].F==b[k].F) ++k;
				if(k!=m) {
					for(; j<k; ++j) {
						adj[b[j].S].push_back(b[k].S);
						adjr[b[k].S].push_back(b[j].S);
					}
				}
				j = k-1;
			}
	}

	rep(i, m)
		if(!mark[i])
			DFSt(i);

	fill_n(mark, m, 0);
	for(int i=m-1; i>=0; --i)
		if(!mark[v[i]]) {
			int x = v[i];
			mark[x] = 1;
			rep(i, Size(adjr[x]))
				if(!mark[adjr[x][i]]) {
					cout << -1 << endl;
					return 0;
				}
		}

	for(int i=m-1; i>=0; --i)
		cout << v[i]+1 << ' ';
	cout << endl;

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define forn(a,b,c) for(int (a)=(b);(a)<(c);(a)++)
#define forr(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define SET(A,b) memset(A,b,sizeof (A) )
#define SIZE(A) ((int)(A).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define num(a) (1LL<<(a))
using namespace std;

typedef double db;
typedef long long Lint;
typedef pair<int,int> ii;
typedef pair<Lint,Lint> Lii;
const int MAXN = 400010;

ii ar[MAXN];

vector<int> G[MAXN];

int ch[MAXN];
int used[MAXN];

int f(int k,int t){

	if(used[k]==1)	return 1;
	if(used[k]==2)	return 0;
	used[k]=1;
	int rev=0;
	forn(i,0,SIZE(G[k]))
		rev=max(rev,f(G[k][i],t));
	used[k]=2;
	return rev;

}

int main(){

	int N,M,m,cnt,tmp;

	scanf("%d %d",&N,&M);

	cnt=M;

	forn(i,0,N){
		m=M;
		forn(j,0,m)
		{
			scanf(" %d",&ar[j].fi);
			if(ar[j].fi==-1)
				ar[j].fi=2e9;
			ar[j].se=j;
		}
		sort(ar,ar+m);
		while(ar[m-1].fi==(int)2e9)
			m--;
		forn(j,0,m){
			if(j && ar[j].fi!=ar[j-1].fi)
				cnt++;
			//G[cnt].pb(ar[j].se);
			G[ar[j].se].pb(cnt);
			ch[cnt]++;
		}
		tmp=cnt+1;
		forr(j,m-2,0){
			if(ar[j].fi!=ar[j+1].fi)
				tmp--;
			//G[ar[j].se].pb(tmp);
			if(tmp<=cnt){
				ch[ar[j].se]++;
				G[tmp].pb(ar[j].se);
			}
		}
		cnt++;
	}
	forn(i,0,M)
	{
		if(f(i,i+1))
		{
			printf("-1\n");
			return 0;
		}
	}
	queue<int> Q;

	forn(i,0,N)
		if(ch[i]==0)
			Q.push(i);
	vector<int> res;
	while(!Q.empty()){
		tmp=Q.front();
		Q.pop();
		if(tmp<M)
			res.pb(tmp+1);
		forn(i,0,SIZE(G[tmp]))
		{
			ch[G[tmp][i]]--;
			if(ch[G[tmp][i]]==0)
				Q.push(G[tmp][i]);
		}
	}
	forr(i,M-1,0)
		printf("%d ",res[i]);
	puts("");
	return 0;

}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define forn(a,b,c) for(int (a)=(b);(a)<(c);(a)++)
#define forr(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define SET(A,b) memset(A,b,sizeof (A) )
#define SIZE(A) ((int)(A).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define num(a) (1LL<<(a))
using namespace std;

typedef double db;
typedef long long Lint;
typedef pair<int,int> ii;
typedef pair<Lint,Lint> Lii;
const int MAXN = 1000010;

ii ar[MAXN];

vector<int> G[MAXN];

int ch[MAXN];
int used[MAXN];

int f(int k,int t){

	if(used[k]==1)	return 1;
	if(used[k]==2)	return 0;
	used[k]=1;
	int rev=0;
	forn(i,0,SIZE(G[k]))
		rev=max(rev,f(G[k][i],t));
	used[k]=2;
	return rev;

}

int main(){

	int N,M,m,cnt,tmp;

	scanf("%d %d",&N,&M);

	cnt=M;

	forn(i,0,N){
		m=M;
		forn(j,0,m)
		{
			scanf(" %d",&ar[j].fi);
			if(ar[j].fi==-1)
				ar[j].fi=2e9;
			ar[j].se=j;
		}
		sort(ar,ar+m);
		while(ar[m-1].fi==(int)2e9)
			m--;
		forn(j,0,m){
			if(j && ar[j].fi!=ar[j-1].fi)
				cnt++;
			G[ar[j].se].pb(cnt);
			ch[cnt]++;
		}
		tmp=cnt+1;
		forr(j,m-2,0){
			if(ar[j].fi!=ar[j+1].fi)
				tmp--;
			if(tmp<=cnt){
				ch[ar[j].se]++;
				G[tmp].pb(ar[j].se);
			}
		}
		cnt++;
	}
	forn(i,0,M)
	{
		if(f(i,i+1))
		{
			printf("-1\n");
			return 0;
		}
	}
	queue<int> Q;

	forn(i,0,N)
		if(ch[i]==0)
			Q.push(i);
	vector<int> res;
	res.clear();
	while(!Q.empty()){
		tmp=Q.front();
		Q.pop();
		if(tmp<M)
			res.pb(tmp+1);
		forn(i,0,SIZE(G[tmp]))
		{
			ch[G[tmp][i]]--;
			if(ch[G[tmp][i]]==0)
				Q.push(G[tmp][i]);
		}
	}
	forr(i,SIZE(res)-1,0)
		printf("%d ",res[i]);
	puts("");
	return 0;

}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define forn(a,b,c) for(int (a)=(b);(a)<(c);(a)++)
#define forr(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define SET(A,b) memset(A,b,sizeof (A) )
#define SIZE(A) ((int)(A).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define num(a) (1LL<<(a))
using namespace std;

typedef double db;
typedef long long Lint;
typedef pair<int,int> ii;
typedef pair<Lint,Lint> Lii;
const int MAXN = 1000010;

ii ar[MAXN];

vector<int> G[MAXN];

int ch[MAXN];
int used[MAXN];

int f(int k,int t){

	if(used[k]==1)	return 1;
	if(used[k]==2)	return 0;
	used[k]=1;
	int rev=0;
	forn(i,0,SIZE(G[k]))
		rev=max(rev,f(G[k][i],t));
	used[k]=2;
	return rev;

}

int main(){

	int N,M,m,cnt,tmp;

	scanf("%d %d",&N,&M);

	cnt=M;

	forn(i,0,N){
		m=M;
		forn(j,0,m)
		{
			scanf(" %d",&ar[j].fi);
			if(ar[j].fi==-1)
				ar[j].fi=2e9;
			ar[j].se=j;
		}
		sort(ar,ar+m);
		while(ar[m-1].fi==(int)2e9)
			m--;
		forn(j,0,m){
			if(j && ar[j].fi!=ar[j-1].fi)
				cnt++;
			//G[cnt].pb(ar[j].se);
			G[ar[j].se].pb(cnt);
			ch[cnt]++;
		}
		tmp=cnt+1;
		forr(j,m-2,0){
			if(ar[j].fi!=ar[j+1].fi)
				tmp--;
			//G[ar[j].se].pb(tmp);
			if(tmp<=cnt){
				ch[ar[j].se]++;
				G[tmp].pb(ar[j].se);
			}
		}
		cnt++;
	}
	forn(i,0,M)
	{
		if(f(i,i+1))
		{
			printf("-1\n");
			return 0;
		}
	}
	queue<int> Q;

	forn(i,0,N)
		if(ch[i]==0)
			Q.push(i);
	vector<int> res;
	while(!Q.empty()){
		tmp=Q.front();
		Q.pop();
		if(tmp<M)
			res.pb(tmp+1);
		forn(i,0,SIZE(G[tmp]))
		{
			ch[G[tmp][i]]--;
			if(ch[G[tmp][i]]==0)
				Q.push(G[tmp][i]);
		}
	}
	forr(i,M-1,0)
		printf("%d ",res[i]);
	puts("");
	return 0;

}