//#define _DEBUG
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef long long ll;
int main()
{
#ifdef _DEBUG
    freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    rush()
    {
        ll n;
        cin >> n;
        if (n <= 14) {
            cout << "NO" << endl;
            continue;
        }
        ll y = n % 14;
        if (y <= 6 && y != 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


//#define _DEBUG
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef long long ll;
int main()
{
#ifdef _DEBUG
    freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    rush()
    {
        int n;
        cin >> n;
        if (n <= 14) {
            cout << "NO" << endl;
            continue;
        }
        int height = n / 14;
        if (n % 14 <= 6 && n % 14 != 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


//#define _DEBUG
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef long long ll;
int main()
{
#ifdef _DEBUG
    freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    rush()
    {
        ll n;
        cin >> n;
        ll height = n / 14;
        if ((n - height * 14) <= 6) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


//#define _DEBUG
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef long long ll;
int main()
{
#ifdef _DEBUG
    freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    rush()
    {
        int n;
        cin >> n;
        if (n <= 14) {
            cout << "NO" << endl;
            continue;
        }
        int y = n % 14;
        if (y <= 6 && y != 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


//#define _DEBUG
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef long long ll;
int main()
{
#ifdef _DEBUG
    freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    rush()
    {
        int n;
        cin >> n;
        if (n <= 14) {
            cout << "NO" << endl;
            continue;
        }
        int height = n / 14;
        if ((n - height * 14) <= 6 && (n - height * 14) >= 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


#include <iostream>
using namespace std;

int main()
{
  int queries;
  long long int x;
  bool state = false;
  int array[] = {15, 16, 17, 18, 19, 20};
  cin >> queries;
  while(queries--)
  {
    state = false;
    cin >> x;
    if(x < 15)
    {
      if(x % 14 == 0)
        state = true;
    }
    else
    {
      for(int i = 0; i < 6; i++)
      {
        if((x - array[i]) % 14 == 0)
        {
          state = true;
          break;
        }
      }
    }
    if(state == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main()
{
  int queries;
  long long int x;
  bool state = false;
  int array[] = {15, 16, 17, 18, 19, 20};
  cin >> queries;
  while(queries--)
  {
    state = false;
    cin >> x;
    if(x < 15)
    {
        state = false;
    }
    else if(x >= 15 && x <= 20)
    {
      state = true;
    }
    else
    {
      for(int i = 0; i < 6; i++)
      {
        if((x - array[i]) % 14 == 0)
        {
          state = true;
          break;
        }
      }
    }
    if(state == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main()
{
  int queries;
  long long int x;
  bool state = false;
  int array[] = {15, 16, 17, 18, 19, 20};
  cin >> queries;
  while(queries--)
  {
    state = false;
    cin >> x;
    if(x < 15)
    {
        state = false;
    }
    else if(x >= 15 && x <= 20)
    {
      state == true;
    }
    else
    {
      for(int i = 0; i < 6; i++)
      {
        if((x - array[i]) % 14 == 0)
        {
          state = true;
          break;
        }
      }
    }
    if(state == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main()
{
  int queries;
  long long int x;
  bool state = false;
  int array[] = {15, 16, 17, 18, 19, 20};
  cin >> queries;
  while(queries--)
  {
    state = false;
    cin >> x;
    for(int i = 0; i < 6; i++)
    {
      if((x - array[i]) % 14 == 0)
      {
        state = true;
        break;
      }
    }
    if(state == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline void solve(){
    ll x;
    cin >> x;
    int one = x / 14, six = x / 14, two = x / 14, four = x / 14, three = x / 14, five = x / 14;
    if(one * 14 + 1 == x || six * 14 + 6 == x || two * 14 + 2 == x || four * 14 + 4 == x || three * 14 + 3 == x || five * 14 + 5 == x){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return;
}

signed main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline void solve(){
    ll x;
    cin >> x;
    if(x % (ll)14 > (ll)0 && x % (ll)14 <= (ll)6) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}

signed main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h> using namespace std; typedef long long ll; inline void solve(){ ll x; cin >> x; if(x % (ll)14 > (ll)0 && x % (ll)14 <= (ll)6 && x > 14) cout << "YES" << endl; else cout << "NO" << endl; return;} signed main(){ int t; cin >> t; while(t--) solve(); return 0;}


#include <bits/stdc++.h>
using namespace std; typedef long long ll; inline void solve(){ ll x; cin >> x; if(x % (ll)14 > (ll)0 && x % (ll)14 <= (ll)6 && x > 14) cout << "YES" << endl; else cout << "NO" << endl; return;} signed main(){ int t; cin >> t; while(t--) solve(); return 0;}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline void solve(){
    ll x;
    cin >> x;
    if(x % 14 > 0 && x % 14 <= 6) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}

signed main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = ceil((pom-6) / 14.0);
            int y = b-1;
            bool moze = false;

              // cout << "BBBBBBBBBBB "  <<  b << endl;

                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;

                }
               //cout << "BBBBBBBBBBB "  <<  b << endl;
                b++;

            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
            //cout << "cccccccccccccccc staaaaaa";

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = ceil((pom-7) / 14.0);
            int y = b-1;
            bool moze = false;

              // cout << "BBBBBBBBBBB "  <<  b << endl;

                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;

                }
               //cout << "BBBBBBBBBBB "  <<  b << endl;
                b++;

            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
            //cout << "cccccccccccccccc staaaaaa";

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = floor((pom-6) / 14.0);
            int y = b-1;
            bool moze = false;
            while(b <= (pom-1)/14 )
            {
                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                    break;
                }

                b++;
            }
            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
       cin >> pom;
       if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else
        {
      long long  int b = ceil((pom-7)/14.0);
       //cout << "BBBBBBB " << b << endl;
        long long int a = 14*b + 7;
        //cout << "razzzzz " << a-b << endl;

        if(a - pom >=1 && a-pom <= 6)
            cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = floor((pom-6) / 14.0);

            bool moze = false;

                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                }

               b++;

               lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                }
            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
       cin >> pom;
       if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else
        {
       int b = ceil((pom-7)/14.0);
       //cout << "BBBBBBB " << b << endl;
        long long int a = 14*b + 7;
        //cout << "razzzzz " << a-b << endl;

        if(a - pom >=1 && a-pom <= 6)
            cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = floor((pom-6) / 14.0);
            int y = b-1;
            bool moze = false;
            while(b <= (pom-1)/14 )
            {
                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                    break;
                }

                b++;
            }
            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
       cin >> pom;
       int b = ceil((pom-7)/14.0);
       //cout << "BBBBBBB " << b << endl;
        long long int a = 14*b + 7;
        //cout << "razzzzz " << a-b << endl;
        if(a - pom >=1 && a-pom <= 6)
            cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = 2;
            bool moze = false;
            while(b*21-(b-1)*7-6 <= pom)
            {
                if((b*21-(b-1)*7)-pom <= 6 && (b*21-(b-1)*7)-pom >= 1)
                {
                    moze = true;
                    break;
                }

                b++;
            }
            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
       cin >> pom;
       if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else
        {
      long long  int b = ceil((pom-6)/14.0);
       //cout << "BBBBBBB " << b << endl;
        long long int a = 14*b + 7;
        //cout << "razzzzz " << a-b << endl;

        if(a - pom >=1 && a-pom <= 6)
            cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
       cin >> pom;
       if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else
        {
      long long  int b = ceil((long double)(pom-7)/14.0);
       //cout << "BBBBBBB " << b << endl;
        long long int a = 14*b + 7;
        //cout << "razzzzz " << a-b << endl;

        if(a - pom >=1 && a-pom <= 6)
            cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = ceil((pom-6) / 14.0);
            int y = b-1;
            bool moze = false;

              // cout << "BBBBBBBBBBB "  <<  b << endl;
            while(pom >= 14*b+1 )
            {
                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                    break;
                }
               //cout << "BBBBBBBBBBB "  <<  b << endl;
                b++;
            }
            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom < 15)
        {
            cout << "NO" << endl;
            continue;
        }
        else if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = ceil((pom-6) / 14.0);
            int y = b-1;
            bool moze = false;

              // cout << "BBBBBBBBBBB "  <<  b << endl;
            while(pom >= 14*b+1 )
            {
                int lo = (b*21-(b-1)*7);
                if(lo > pom &&  lo-pom <= 6 && lo-pom >= 1)
                {
                    moze = true;
                    break;
                }
               cout << "BBBBBBBBBBB "  <<  b << endl;
                b++;
            }
            //cout << "AAAAAAAAAAAAA " << y << endl;

            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    long long int pom;

    for(int i = 0; i < n; i++)
    {
        cin >> pom;
        if(pom <= 20 && pom >= 15)
            {
                cout << "YES" << endl;
                continue;
            }
        else
        {
            int b = ceil((pom-6) / 14.0);
            bool moze = false;
            while(b*21-(b-1)*7-6 <= pom)
            {
                if((b*21-(b-1)*7)-pom <= 6 && (b*21-(b-1)*7)-pom >= 1)
                {
                    moze = true;
                    break;
                }

                b++;
            }
            if(moze)
                cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }

        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) int i; for(i=a;i<b;++i)
#define rf(i,a,b) for(int i = a;i>=b;--i)
#define ww ll t; cin>>t; while(t--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

using namespace std;

int main()
{
    ww
    {
        int n;
        cin>>n;
        if(n%14<7&&n%14>0&&n/14>0)
            yes;
        else
            no;
    }

}


#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) int i; for(i=a;i<b;++i)
#define rf(i,a,b) for(int i = a;i>=b;--i)
#define ww ll t; cin>>t; while(t--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

using namespace std;

int main()
{
    ww
    {
        ll n;
        cin>>n;
        if(n%14<7&&n%14>0&&n/14>0)
            yes;
        else
            no;
    }

}


#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) int i; for(i=a;i<b;++i)
#define rf(i,a,b) for(int i = a;i>=b;--i)
#define ww ll t; cin>>t; while(t--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

using namespace std;

int main()
{
    ww
    {
        int n;
        cin>>n;
        if(n%14<7&&n%14>0)
            yes;
        else
            no;
    }

}


#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) int i; for(i=a;i<b;++i)
#define rf(i,a,b) for(int i = a;i>=b;--i)
#define ww ll t; cin>>t; while(t--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

using namespace std;

int main()
{
    ww
    {
        int n;
        cin>>n;
        if(n%14<7&&n%14>0&&n>14)
            yes;
        else
            no;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, x, l,s=14,i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
        if((x%14)>=0&&(x%14)<=6&&(x>=15))
        {
        	cout<<"YES"<<endl;
        }else
        {
        	cout<<"NO"<<endl;
        }

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, x, l,s=14,i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
        if((x%14)>=0&&(x%14)<=6)
        {
        	cout<<"YES"<<endl;
        }else
        {
        	cout<<"NO"<<endl;
        }

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, x, l,s=14,i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
        if(x%14<=6)
        {
        	cout<<"YES"<<endl;
        }else
        {
        	cout<<"NO"<<endl;
        }

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n, x, l,s=14,i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
        if((x%14)>=1&&(x%14)<=6&&(x>=15))
        {
        	cout<<"YES"<<endl;
        }else
        {
        	cout<<"NO"<<endl;
        }

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, x, l,s=14,i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
        if((x%14)>=1&&(x%14)<=6&&(x>=15))
        {
        	cout<<"YES"<<endl;
        }else
        {
        	cout<<"NO"<<endl;
        }

	}

	return 0;
}


#include <iostream>

using namespace std;

void program() {
    long long n; cin >> n;
    if (n < 7) {
        cout << "NO" << endl;
        return;
    }
    long long rem = n % 14;
    if (rem < 7 && rem > 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main()
{
    int t; cin >> t;
    while (t--) {program();}
    return 0;
}


#include <iostream>

using namespace std;

void program() {
    int n; cin >> n;
    if (n < 7) {
        cout << "NO" << endl;
        return;
    }
    int rem = n % 14;
    if (rem < 7 && rem >= 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main()
{
    int t; cin >> t;
    while (t--) {program();}
    return 0;
}


#include <iostream>

using namespace std;

void program() {
    int n; cin >> n;
    if (n < 7) {
        cout << "NO" << endl;
        return;
    }
    int rem = n % 14;
    if (rem < 7 && rem > 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main()
{
    int t; cin >> t;
    while (t--) {program();}
    return 0;
}


#include <iostream>

using namespace std;

void program() {
    int n; cin >> n;
    int rem = n % 14;
    if (rem < 7 && rem >= 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main()
{
    int t; cin >> t;
    while (t--) {program();}
    return 0;
}


#include <iostream>

using namespace std;

void program() {
    int n; cin >> n;
    if (n < 7) {
        cout << "NO" << endl;
        return 0;
    }
    int rem = n % 14;
    if (rem < 7 && rem >= 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main()
{
    int t; cin >> t;
    while (t--) {program();}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		if(x==0)printf("NO\n");
		cin>>x;
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x==0)printf("NO\n");
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	while(n--)
	{
		cin>>x;
		if(x<14)printf("NO\n");
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
LL x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		x%=14;
		x+=14;
		if(x<=20 && x>=15)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x==0)printf("YES\n");
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		if(!x)printf("YES\n");
		cin>>x;
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	while(n--)
	{
		cin>>x;
		if(x==0){printf("YES\n");continue;}
		if(x<14){	printf("NO\n");continue;}
		x%=14;
		if(x<=6 && x>=1){printf("YES\n");continue ;}
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define mid ((l+r)>>1)
#define FOR(u,i) for(int i=head[u],v=E[head[u]].to;i;i=E[i].nxt,v=E[i].to)
const int N=1e5+10,inf=0x3f3f3f3f;
int n,m;
unsigned long long x;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		x%=14;
		if(x<=6 && x>=1)printf("YES\n");
		else printf("NO\n");
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	solve();
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int64_t n;
    cin>>n;
    for(int64_t i=0; i<n; i++)
    {
        int64_t x;
        cin>>x;
        if(x%14<=6 && x>14 && x%14!=0)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(x%14<=6)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(x%14<=6 && x>14)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int64_t n;
    cin>>n;
    for(int64_t i=0; i<n; i++)
    {
        int64_t x;
        cin>>x;
        if(x%14<=6 && x>14)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(x%14<=6 && x>14 && x%14!=0)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        long long number;
        cin>>number;
        int yes=0;
        for(int j=15;j<21;j++)
        {
            long long int data;
            data=number-j;
            if(data%14==0)
            {
                yes=1;
                break;
            }
        }
        if(yes==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        long long number;
        cin>>number;
        int yes=0;
        for(int j=15;j<22;j++)
        {
            long long int data;
            data=number-j;
            if(data%14==0)
            {
                yes=1;
                break;
            }
        }
        if(yes==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        long long number;
        cin>>number;
        int data=number%14;

        if(data>0 && data<7 && number>6)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        long long number;
        cin>>number;
        int data=number%14;

        if(data>0 && data<7)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        long long number;
        cin>>number;
        cout<<number<<endl;
        int yes=0;
        for(int j=15;j<21;j++)
        {
            long long int data;
            data=number-j;
            if(data%14==0)
            {
                yes=1;
                break;
            }
        }
        if(yes==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f,x,y,z,n;
    cin>>t;

    for(int j=0; j<t; j++)
    {
        cin>>n;
        f=0;
        if(n>21)
        {
            y=n/14;
            z=n-y*14;
            if(z>=1&&z<=6)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=6; i++)
            {
                if(21-i==n)
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,f,x,y,z,n;
    cin>>t;

    for(int j=0; j<t; j++)
    {
        cin>>n;
        f=0;
        if(n>21)
        {
            y=n/14;
            z=n-y*14;
            if(z>=1&&z<=6)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=6; i++)
            {
                if(21-i==n)
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f;
    cin>>t;
    ll ar[t+1];
    for(int i=0; i<t; i++)
    {
        cin>>ar[i];
    }

    //7 7 7

    for(int j=0; j<t; j++)
    {
        ll x,y,z,m,dic,f=0;
        if(ar[j]>21)
        {
            x=ar[j]/21;
            //cout<<x<<endl;
            if(x%21==0)
            {
                m=x;
            }
            else
            {
                m=x+1;
            }
            //cout<<m<<endl;
            dic=21*m;
            //cout<<dic<<endl;
            y=7*(m-1);
            //cout<<y<<endl;
            z=dic-y;
            //cout<<z<<endl;
            for(int i=1; i<=7; i++)
            {
                //cout<<z-i<<endl;
                if(z-i==ar[j])
                {
                    //cout<<"A"<<endl;
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=7; i++)
            {
                if(21-i==ar[j])
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f;
    cin>>t;
    ll ar[t+1];
    for(int i=0; i<t; i++)
    {
        cin>>ar[i];
    }

    //7 7 7

    for(int j=0; j<t; j++)
    {
        ll x,y,z,m,dic,f=0;
        if(ar[j]>21)
        {
            x=ar[j]/21;
            cout<<x<<endl;
            if(x%21==0)
            {
                m=x;
            }
            else
            {
                m=x+1;
            }
            cout<<m<<endl;
            dic=21*m;
            cout<<dic<<endl;
            y=7*(m-1);
            cout<<y<<endl;
            z=dic-y;
            cout<<z<<endl;
            for(int i=1; i<7; i++)
            {
                cout<<z-i<<endl;
                if(z-i==ar[j])
                {
                    cout<<"A"<<endl;
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=6; i++)
            {
                if(21-i==ar[j])
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f;
    cin>>t;
    ll ar[t+1];
    for(int i=0; i<t; i++)
    {
        cin>>ar[i];
    }

    //7 7 7

    for(int j=0; j<t; j++)
    {
        ll x,y,z,m,dic,f=0;
        if(ar[j]>21)
        {
            x=ar[j]/21;
            //cout<<x<<endl;
            if(x%21==0)
            {
                m=x;
            }
            else
            {
                m=x+1;
            }
            //cout<<m<<endl;
            dic=21*m;
            //cout<<dic<<endl;
            y=7*(m-1);
            //cout<<y<<endl;
            z=dic-y;
            //cout<<z<<endl;
            for(int i=1; i<=7; i++)
            {
                //cout<<z-i<<endl;
                if(z-i==ar[j])
                {
                    //cout<<"A"<<endl;
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=6; i++)
            {
                if(21-i==ar[j])
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f,x,y,z;
    cin>>t;
    ll ar[t+1];
    for(int i=0; i<t; i++)
    {
        cin>>ar[i];
    }

    for(int i=0;i<t;i++)
    {
        y=ar[i]/14;
        z=ar[i]-y*14;
        if(z>=1&&z<=6)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t,f;
    cin>>t;
    ll ar[t+1];
    for(int i=0; i<t; i++)
    {
        cin>>ar[i];
    }

    //7 7 7

    for(int j=0; j<t; j++)
    {
        ll x,y,z,m,dic,f=0;
        if(ar[j]>21)
        {
            x=ar[j]/21;
            //cout<<x<<endl;
            if(x%21==0)
            {
                m=x;
            }
            else
            {
                m=x+1;
            }
            //cout<<m<<endl;
            dic=21*m;
            //cout<<dic<<endl;
            y=7*(m-1);
            //cout<<y<<endl;
            z=dic-y;
            //cout<<z<<endl;
            for(int i=1; i<7; i++)
            {
                //cout<<z-i<<endl;
                if(z-i==ar[j])
                {
                    //cout<<"A"<<endl;
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
        else
        {
            for(int i=1; i<=6; i++)
            {
                if(21-i==ar[j])
                {
                    f=1;
                }
            }
            if(f==1)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }

    }
    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin>>t;
  vector<long long>v(t, 0);
  for(int i=0;i<t;i++)
  {
    cin>>v[i];
  }
  for(int i=0;i<t;i++)
  {
    v[i]-=15;
    if(v[i]%14<=5)
    {
      cout<<"YES"<<"\n";
    }
    else
    {
      cout<<"NO"<<"\n";
    }
  }
    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin>>t;
  long long num;
  for(int i=0;i<t;i++)
  {
    cin>>num;
    num-=15;
    long long d = num/14;
    if(num>=d*14 && num<=d*14+5 && num>=0)
    {
      cout<<"YES"<<"\n";
    }
    else
    {
      cout<<"NO"<<"\n";
    }
  }

    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin>>t;
  long long num;
  for(int i=0;i<t;i++)
  {
    cin>>num;
    num-=15;

    if(num%14<=5)
    {
      cout<<"YES"<<"\n";
    }
    else
    {
      cout<<"NO"<<"\n";
    }
  }

    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin>>t;
  long long num;
  for(int i=0;i<t;i++)
  {
    cin>>num;
    num-=15;
    long long d = num/14;
    if(num>=d*14 && num<=d*14+5)
    {
      cout<<"YES"<<"\n";
    }
    else
    {
      cout<<"NO"<<"\n";
    }
  }

    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin>>t;
  long long num;
  for(int i=0;i<t;i++)
  {
    cin>>num;
    num-=15;
    long long d = num/14;
    if(num>=d*14 && num<=d*14+5 && num>0)
    {
      cout<<"YES"<<"\n";
    }
    else
    {
      cout<<"NO"<<"\n";
    }
  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
      int d,t,x;
      cin>>x;

      t=x%14;

      if(x>=14 && (1<=t && t<=6)) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
    }

    return 0;

}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

int m, n, id[100100], tmp[100100];
vector <int> a[100100];

int cmp(int id)
{
	for (int i = 1; i <= m; i++)
		if (tmp[i] >= 0 && a[i][id] >= 0 && tmp[i] != a[i][id])
		{
			if (a[i][id] < tmp[i]) return -1;
			return 1;
		}
	return 0;
}

int Rand(int z)
{
	if (z < 30000) return rand() % z;
	int k = int(sqrt(z));
	return rand() % k * k + rand() % k;
}

void mySort(int l, int r)
{
	int i = l, j = r, x = l + Rand(r - l + 1);
	for (int z = 1; z <= m; z++) tmp[z] = a[z][x];
	do
	{
		while (cmp(id[i]) < 0) i++;
		while (cmp(id[j]) > 0) j--;
		if (i <= j) swap(id[i++], id[j--]);
	} while (i <= j);
	if (i < r) mySort(i, r);
	if (l < j) mySort(l, j);
}

int cmpCol(int u, int v)
{
	for (int i = 1; i <= m; i++)
		if (a[i][u] >= 0 && a[i][v] >= 0 && a[i][u] > a[i][v])
			return 1;
	return 0;
}

int main()
{
	cin >> m >> n;
	for (int i = 1; i <= m; i++) a[i].resize(n + 2);
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);

	for (int i = 1; i <= n; i++) id[i] = i;
	int M = n;
	for (int j = n; j; j--)
	{
		int has = 0;
		for (int i = 1; i <= m; i++)
			if (a[i][j] >= 0)
			{
				has = 1;
				break;
			}
		if (!has) swap(id[j], id[M--]);
	}

	if (M > 1) mySort(1, M);
	for (int i = 1; i < n; i++)
		if (cmpCol(id[i], id[i + 1]) > 0)
		{
			puts("-1");
			return 0;
		}
	for (int i = 1; i <= n; i++) cout << id[i] << ' ';
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define fr(a,b,c) for (int a=b;a<=c;a++)
#define frr(a,b,c) for (int a=b;a>=c;a--)
#define rep(a,b) for (int a=0;a<b;a++)
#define repp(a,b) for (int a=b-1;a>=0;a--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define reset(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define oo 1000111222
#define maxN 1
using namespace std;

int m, n, id[100100], tmp[100100];
vector <int> a[100100];

int cmp(int id)
{
	for (int i = 1; i <= m; i++)
		if (tmp[i] >= 0 && a[i][id] >= 0 && tmp[i] != a[i][id])
		{
			if (a[i][id] < tmp[i]) return -1;
			return 1;
		}
	return 0;
}

void mySort(int l, int r)
{
	int i = l, j = r, x = l + rand() % (r - l + 1);
	for (int z = 1; z <= m; z++) tmp[z] = a[z][x];
	do
	{
		while (cmp(id[i]) < 0) i++;
		while (cmp(id[j]) > 0) j--;
		if (i <= j) swap(id[i++], id[j--]);
	} while (i <= j);
	if (i < r) mySort(i, r);
	if (l < j) mySort(l, j);
}

int cmpCol(int u, int v)
{
	for (int i = 1; i <= m; i++)
		if (a[i][u] >= 0 && a[i][v] >= 0 && a[i][u] > a[i][v])
			return 1;
	return 0;
}

int main()
{
	cin >> m >> n;
	for (int i = 1; i <= m; i++) a[i].resize(n + 2);
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);

	for (int i = 1; i <= n; i++) id[i] = i;
	int m = n;
	for (int j = n; j; j--)
	{
		int has = 0;
		for (int i = 1; i <= m; i++)
			if (a[i][j] >= 0)
			{
				has = 1;
				break;
			}
		if (!has) swap(id[j], id[m--]);
	}

	if (m > 1) mySort(1, m);
	for (int i = 1; i < n; i++)
		if (cmpCol(id[i], id[i + 1]) > 0)
		{
			puts("-1");
			return 0;
		}
	for (int i = 1; i <= n; i++) cout << id[i] << ' ';
}


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

using namespace std;

int n, m;
vector <int> row[200000];
int perm[200000];

void read_input()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        row[i].push_back (0);
        for (int j = 1; j <= m; j++)
        {
            int a;
            scanf ("%d", &a);
            row[i].push_back (a);
        }
    }
    for (int j = 1; j <= m; j++)
    {
        perm[j] = j;
    }
}

int r;
bool cmp (int i, int j)
{
    return row[r][perm[i]] < row[r][perm[j]];
}

void sort_col()
{
    for (int i = 1; i <= n; i++)
    {
        r = i;
        vector <int> a, b;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] != -1)
            {
                a.push_back (j);
                b.push_back (j);
            }
        }
        sort (b.begin(), b.end(), cmp);
        vector <int> nperm;
        for (int j = 0; j < b.size(); j++)
        {
            nperm.push_back (perm[a[j]]);
        }
        for (int j = 0; j < b.size(); j++)
        {
            perm[b[j]] = nperm[j];
        }
    }
}

bool check()
{
    for (int i = 1; i <= n; i++)
    {
        int last = -1;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] == -1) continue;
            if (row[i][perm[j]] >= last)
            {
                last = row[i][perm[j]];
            }
            else
            {
                return false;
            }
        }
    }
    return true;
}

void print_ans()
{
    for (int i = 1; i <= m; i++)
    {
        printf ("%d", perm[i]);
        if (i != m) printf (" ");
        else        printf ("\n");
    }
}

int main()
{
    read_input();
    sort_col();
    if (check())
    {
        print_ans();
    }
    else
    {
        printf ("-1\n");
    }
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

int n, m;
vector <int> row[300000];
vector <int> down[300000];
vector <int> up[300000];
bool use[300000];
int deg[300000];
vector <int> ans;
int cur_max = 0;

void read_input()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        row[i].push_back (0);
        for (int j = 1; j <= m; j++)
        {
            int a;
            scanf ("%d", &a);
            row[i].push_back (a);
        }
    }
    memset (deg, 0, sizeof (deg));
    memset (use, 0, sizeof (use));
}

int r;
bool cmp (int i, int j)
{
    return row[r][i] < row[r][j];
}

void make_graph()
{
    int cur = n * m + 1;
    for (int i = 1; i <= n; i++)
    {
        r = i;
        vector <int> keep;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][j] != -1) keep.push_back(j);
        }
        sort (keep.begin(), keep.end(), cmp);
        // fix ties!
        for (int i = 0; i < keep.size(); i++)
        {
            if (i != 0 && row[r][keep[i]] != row[r][keep[i - 1]])
            {
                cur++;
            }
            deg[cur + 1]++;
            deg[keep[i]]++;
            up[cur].push_back (keep[i]);
            up[keep[i]].push_back (cur + 1);
        }
        cur += 2;
        cur_max = max (cur, cur_max);
    }
}

bool find_ans()
{
    priority_queue <pair <int, int> > pq;
    for (int i = 1; i <= cur_max; i++)
    {
        pq.push (make_pair(-deg[i], i));
    }
    while (!pq.empty())
    {
        pair <int, int> p = pq.top();
        pq.pop();
        int v = p.second;
        if (use[v]) continue;
        if (v <= m) ans.push_back(v);
        use[v] = true;
        // printf ("%d %d\n", v, deg[v]);
        for (int i = 0; i < up[v].size(); i++)
        {
            // printf ("%d->%d, %d\n", v, up[v][i], use[up[v][i]]);
            if (use[up[v][i]]) return false;
            deg[up[v][i]]--;
            pq.push(make_pair (-deg[up[v][i]], up[v][i]));
        }
    }
    return true;
}

void print_ans()
{
    for (int i = 0; i < m; i++)
    {
        printf ("%d ", ans[i]);
    }
    printf ("\n");
}

int main()
{
    read_input();
    make_graph();
    if (find_ans())
    {
        print_ans();
    }
    else
    {
        printf("-1\n");
    }
}


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

using namespace std;

int n, m;
vector <int> row[200000];
int perm[200000];

void read_input()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        row[i].push_back (0);
        for (int j = 1; j <= m; j++)
        {
            int a;
            scanf ("%d", &a);
            row[i].push_back (a);
        }
    }
    for (int j = 1; j <= m; j++)
    {
        perm[j] = j;
    }
}

int r;
bool cmp (int i, int j)
{
    return row[r][perm[i]] < row[r][perm[j]];
}

void sort_col()
{
    for (int i = 1; i <= n; i++)
    {
        r = i;
        vector <int> a, b;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] != -1)
            {
                a.push_back (j);
                b.push_back (j);
            }
        }
        sort (b.begin(), b.end(), cmp);
        vector <int> nperm;
        for (int i = 0; i < b.size(); i++)
        {
            nperm.push_back (perm[a[i]]);
        }
        for (int i = 0; i < b.size(); i++)
        {
            perm[b[i]] = nperm[i];
        }
    }
}

bool check()
{
    for (int i = 1; i <= n; i++)
    {
        int last = -1;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] == -1) continue;
            if (row[i][perm[j]] >= last)
            {
                last = row[i][perm[j]];
            }
            else
            {
                return false;
            }
        }
    }
    return true;
}

void print_ans()
{
    for (int i = 1; i <= m; i++)
    {
        printf ("%d", perm[i]);
        if (i != m) printf (" ");
        else        printf ("\n");
    }
}

int main()
{
    read_input();
    sort_col();
    if (check())
    {
        print_ans();
    }
    else
    {
        printf ("-1\n");
    }
}


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

using namespace std;

int n, m;
vector <int> row[200000];
int perm[200000];

void read_input()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        row[i].push_back (0);
        for (int j = 1; j <= m; j++)
        {
            int a;
            scanf ("%d", &a);
            row[i].push_back (a);
        }
    }
    for (int j = 1; j <= m; j++)
    {
        perm[j] = j;
    }
}

int r;
bool cmp (int i, int j)
{
    return row[r][perm[i]] < row[r][perm[j]];
}

void print_ans()
{
    for (int i = 1; i <= m; i++)
    {
        printf ("%d", perm[i]);
        if (i != m) printf (" ");
        else        printf ("\n");
    }
}

void sort_col()
{
    for (int i = 1; i <= n; i++)
    {
        r = i;
        vector <int> a, b;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] != -1)
            {
                a.push_back (j);
                b.push_back (j);
            }
        }
        stable_sort (b.begin(), b.end(), cmp);
        vector <int> nperm;
        for (int j = 0; j < b.size(); j++)
        {
            nperm.push_back (perm[b[j]]);
        }
        for (int j = 0; j < b.size(); j++)
        {
            perm[a[j]] = nperm[j];
        }
        // print_ans();
    }
}

bool check()
{
    for (int i = 1; i <= n; i++)
    {
        int last = -1;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] == -1) continue;
            if (row[i][perm[j]] >= last)
            {
                last = row[i][perm[j]];
            }
            else
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    read_input();
    sort_col();
    if (check())
    {
        print_ans();
    }
    else
    {
        printf ("-1\n");
    }
}


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

using namespace std;

int n, m;
vector <int> row[200000];
int perm[200000];

void read_input()
{
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        row[i].push_back (0);
        for (int j = 1; j <= m; j++)
        {
            int a;
            scanf ("%d", &a);
            row[i].push_back (a);
        }
    }
    for (int j = 1; j <= m; j++)
    {
        perm[j] = j;
    }
}

int r;
bool cmp (int i, int j)
{
    return row[r][perm[i]] < row[r][perm[j]];
}

void print_ans()
{
    for (int i = 1; i <= m; i++)
    {
        printf ("%d", perm[i]);
        if (i != m) printf (" ");
        else        printf ("\n");
    }
}

void sort_col()
{
    for (int i = 1; i <= n; i++)
    {
        r = i;
        vector <int> a, b;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] != -1)
            {
                a.push_back (j);
                b.push_back (j);
            }
        }
        sort (b.begin(), b.end(), cmp);
        vector <int> nperm;
        for (int j = 0; j < b.size(); j++)
        {
            nperm.push_back (perm[b[j]]);
        }
        for (int j = 0; j < b.size(); j++)
        {
            perm[a[j]] = nperm[j];
        }
        // print_ans();
    }
}

bool check()
{
    for (int i = 1; i <= n; i++)
    {
        int last = -1;
        for (int j = 1; j <= m; j++)
        {
            if (row[i][perm[j]] == -1) continue;
            if (row[i][perm[j]] >= last)
            {
                last = row[i][perm[j]];
            }
            else
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    read_input();
    sort_col();
    if (check())
    {
        print_ans();
    }
    else
    {
        printf ("-1\n");
    }
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#define ll long long
const int N=100001;
using namespace std;

pair<int,int> a[N];
set<int> g[N];
vector<int> v1,v2,v;
int vis[N];

bool dfs(int x){
     vis[x]=1;
     set<int>::iterator it;
     for(it=g[x].begin();it!=g[x].end();it++)
         if(vis[*it]<0){
           if(!dfs(*it)) return false;
         }
         else if(vis[*it]==1) return false;
     vis[x]=2;
     v.push_back(x);
     return true;
}

int main(){
    int n,m,i,j,k,p;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[j].first);
            a[j].second=j;
        }
        sort(a,a+m);
        j=0;
        while(a[j].first==-1 && j<m) j++;
        v1.clear();
        if(j<m)
        {  v1.push_back(a[j].second);
           while(j<m-1 && a[j+1].first==a[j].first)
           {  j++;
              v1.push_back(a[j].second);
           }
        }
        j++;
        while(j<m)
        {  v2.clear();
           do{
              v2.push_back(a[j].second);j++;}
           while(j<m && a[j].first==a[j-1].first);
           for(k=0;k<v1.size();k++)
               for(p=0;p<v2.size();p++)
                   g[v1[k]].insert(v2[p]);
           v1=v2;
        }
    }
    memset(vis,-1,sizeof(vis));
    bool ok=true;
    for(i=0;i<m;i++)
        if(vis[i]<0)
          if(!dfs(i)){ok=false;break;}
    if(!ok) printf("-1\n");
    else
    {  for(i=v.size()-1;i>=0;i--)
           printf("%d ",v[i]+1);
    }
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#define ll long long
const int N=100001;
using namespace std;

pair<int,int> a[N];
set<int> g[N];
vector<int> v1,v2,v;
int vis[N];

bool dfs(int x){
     vis[x]=1;
     set<int>::iterator it;
     for(it=g[x].begin();it!=g[x].end();it++)
         if(vis[*it]<0){
           if(!dfs(*it)) return false;
         }
         else if(vis[*it]==1) return false;
     vis[x]=2;
     v.push_back(x);
     return true;
}

int main(){
    int n,m,i,j,k,p;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[j].first);
            a[j].second=j;
        }
        sort(a,a+m);
        j=0;
        while(a[j].first==-1 && j<m) j++;
        v1.clear();
        if(j<m)
        {  v1.push_back(a[j].second);
           while(j<m-1 && a[j+1].first==a[j].first)
           {  j++;
              v1.push_back(a[j].second);
           }
        }
        j++;
        while(j<m)
        {  v2.clear();
           do{
              v2.push_back(a[j].second);j++;}
           while(j<m && a[j].first==a[j-1].first);
           for(k=0;k<v1.size();k++)
               for(p=0;p<v2.size();p++)
                   g[v1[k]].insert(v2[p]);
           v2=v1;
        }
    }
    memset(vis,-1,sizeof(vis));
    bool ok=true;
    for(i=0;i<m;i++)
        if(vis[i]<0)
          if(!dfs(i)){ok=false;break;}
    if(!ok) printf("-1\n");
    else
    {  for(i=v.size()-1;i>=0;i--)
           printf("%d ",v[i]+1);
    }
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#define ll long long
using namespace std;

int n,m;
vector<pair<int,int> > r;
vector<int> g[150005],p;
vector<vector<int> > v;
vector<int> ans;
int visited[150005];
bool f=true;

void dfs(int x){
     visited[x]=1;
     for(int i=0;i<g[x].size();i++){
         if(visited[g[x][i]]==0) dfs(g[x][i]);
         else if(visited[g[x][i]]==1) {f=false;return;}
         if(!f) return;
     }

     visited[x]=2;
     ans.push_back(x);
}

int main(){
    scanf("%d%d",&n,&m);
    int i,j,x;
    int tot=m;
    for(i=0;i<n;i++)
    {   r.clear();
        for(j=0;j<m;j++)
        {   scanf("%d",&x);
            if(x!=-1) r.push_back(make_pair(x,j));
        }
        sort(r.begin(),r.end());
        v.clear();
        for(j=0;j<r.size();j++)
        {   p.clear();
            p.push_back(r[j].second);
            while(j<m-1 && r[j+1].first==r[j].first) {j++;p.push_back(r[j].second);}
            v.push_back(p);
        }
        for(j=0;j<v.size()-1;j++)
        {   if(v[j].size()>=2 && v[j+1].size()>=2)
            {  tot++;
               for(int k=0;k<v[j].size();k++)
                   g[v[j][k]].push_back(tot-1);
               for(int k=0;k<v[j+1].size();k++)
                   g[tot-1].push_back(v[j+1][k]);
            }
            else
            {  for(int k=0;k<v[j].size();k++)
                   for(int q=0;q<v[j+1].size();q++)
                       g[v[j][k]].push_back(v[j+1][q]);
            }
        }
    }
    for(i=0;i<tot;i++){
        if(!f) break;
        if(visited[i]==0) dfs(i);
    }
    if(!f) printf("-1\n");
    else
    for(i=ans.size()-1;i>=0;i--)
        if(ans[i]<m) printf("%d ",ans[i]+1);
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#define ll long long
using namespace std;

int n,m;
vector<pair<int,int> > r;
vector<int> g[150005],p;
vector<vector<int> > v;
vector<int> ans;
int visited[150005];
bool f=true;

void dfs(int x){
     visited[x]=1;
     for(int i=0;i<g[x].size();i++){
         if(visited[g[x][i]]==0) dfs(g[x][i]);
         else if(visited[g[x][i]]==1) {f=false;return;}
         if(!f) return;
     }

     visited[x]=2;
     ans.push_back(x);
}

int main(){
    scanf("%d%d",&n,&m);
    int i,j,x;
    int tot=m;
    for(i=0;i<n;i++)
    {   r.clear();
        for(j=0;j<m;j++)
        {   scanf("%d",&x);
            if(x!=-1) r.push_back(make_pair(x,j));
        }
        sort(r.begin(),r.end());
        v.clear();
        for(j=0;j<r.size();j++)
        {   p.clear();
            p.push_back(r[j].second);
            while(j<m-1 && r[j+1].first==r[j].first) {j++;p.push_back(r[j].second);}
            v.push_back(p);
        }
        for(j=0;j<v.size()-1;j++)
        {   if(v[j].size()>=2 && v[j+1].size()>=2)
            {  tot++;
               for(int k=0;k<v[j].size();k++)
                   g[v[j][k]].push_back(tot-1);
               for(int k=0;k<v[j+1].size();k++)
                   g[tot-1].push_back(v[j+1][k]);
            }
            else
            {  for(int k=0;k<v[j].size();k++)
                   for(int q=0;q<v[j+1].size();q++)
                       g[v[j][k]].push_back(v[j+1][q]);
            }
        }
    }
    for(i=0;i<tot;i++){
        if(!f) break;
        if(visited[i]==0) dfs(i);
    }
    if(!f) printf("-1\n");
    else
    for(i=ans.size()-1;i>=0;i--)
        if(ans[i]<m) printf("%d ",ans[i]+1);
    system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#define ll long long
using namespace std;

int n,m;
vector<pair<int,int> > r;
vector<int> g[200005];
vector<int> ans;
int visited[150005];
bool f=true;

void dfs(int x){//cout<<x<<endl;
     visited[x]=1;
     for(int i=0;i<g[x].size();i++){
         if(visited[g[x][i]]==0) dfs(g[x][i]);
         else if(visited[g[x][i]]==1) {f=false;return;}
         if(!f) return;
     }

     visited[x]=2;
     ans.push_back(x);
}

int main(){
    scanf("%d%d",&n,&m);
    int i,j,x,k;
    int tot=m;
    for(i=0;i<n;i++)
    {   r.clear();
        for(j=0;j<m;j++)
        {   scanf("%d",&x);
            if(x!=-1) r.push_back(make_pair(x,j));
        }
        sort(r.begin(),r.end());
        tot++;
        for(j=0;j<r.size();)
        {
            g[tot-1].push_back(r[j].second);g[r[j].second].push_back(tot);
            for(k=j+1;k<r.size();k++)
                if(r[k].first==r[k-1].first)
                {g[tot-1].push_back(r[k].second);g[r[k].second].push_back(tot);}
                else
                   break;
            j=k;
            tot++;
        }
    }
    //for(i=0;i<=tot;i++){cout<<i<<' '; for(j=0;j<g[i].size();j++) cout<<g[i][j];cout<<endl;}
    for(i=0;i<=tot;i++){
        if(!f) break;
        if(visited[i]==0) dfs(i);
    }
    if(!f) printf("-1\n");
    else
    for(i=ans.size()-1;i>=0;i--)
        if(ans[i]<m) printf("%d ",ans[i]+1);
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#define ll long long
const int N=100001;
using namespace std;

pair<int,int> a[N];
set<int> g[N];
vector<int> v1,v2,v;
int vis[N];

bool dfs(int x){
     vis[x]=1;
     set<int>::iterator it;
     for(it=g[x].begin();it!=g[x].end();it++)
         if(vis[*it]<0){
           if(!dfs(*it)) return false;
         }
         else if(vis[*it]==1) return false;
     vis[x]=2;
     v.push_back(x);
     return true;
}

int main(){
    int n,m,i,j,k,p;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[j].first);
            a[j].second=j;
        }
        sort(a,a+m);
        j=0;
        while(a[j].first==-1 && j<m) j++;
        v1.clear();
        if(j<m)
        {  v1.push_back(a[j].second);
           while(j<m-1 && a[j+1].first==a[j].first)
           {  j++;
              v1.push_back(a[j].second);
           }
        }
        j++;
        while(j<m)
        {  v2.clear();
           do{
              v2.push_back(a[j].second);j++;}
           while(j<m && a[j].first==a[j-1].first);
           for(k=0;k<v1.size();k++)
               for(p=0;p<v2.size();p++)
                   g[v1[k]].insert(v2[p]);
           v2=v1;
        }
    }
    memset(vis,-1,sizeof(vis));
    bool ok=true;
    for(i=0;i<m;i++)
        if(vis[i]<0)
          if(!dfs(i)){ ok=false;break;}
    if(!ok) printf("-1\n");
    else
    {  for(i=v.size()-1;i>=0;i--)
           printf("%d ",v[i]+1);
    }
    system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#define ll long long
using namespace std;

int n,m;
vector<pair<int,int> > r;
vector<int> g[150005],p;
vector<vector<int> > v;
vector<int> ans;
int visited[150005];
bool f=true;

void dfs(int x){
     visited[x]=1;
     for(int i=0;i<g[x].size();i++){
         if(visited[g[x][i]]==0) dfs(g[x][i]);
         else if(visited[g[x][i]]==1) {f=false;return;}
         if(!f) return;
     }

     visited[x]=2;
     ans.push_back(x);
}

int main(){
    scanf("%d%d",&n,&m);
    int i,j,x;
    int tot=m;
    for(i=0;i<n;i++)
    {   r.clear();
        for(j=0;j<m;j++)
        {   scanf("%d",&x);
            if(x!=-1) r.push_back(make_pair(x,j));
        }
        if(r.size()<2) continue;
        sort(r.begin(),r.end());
        v.clear();
        for(j=0;j<r.size();j++)
        {   p.clear();
            p.push_back(r[j].second);
            while(j<m-1 && r[j+1].first==r[j].first) {j++;p.push_back(r[j].second);}
            v.push_back(p);
        }
        for(j=0;j<v.size();j++)
        {   if(j+1==v.size()) break;
            if(v[j].size()>=2 && v[j+1].size()>=2)
            {  tot++;
               for(int k=0;k<v[j].size();k++)
                   g[v[j][k]].push_back(tot-1);
               for(int k=0;k<v[j+1].size();k++)
                   g[tot-1].push_back(v[j+1][k]);
            }
            else
            {  for(int k=0;k<v[j].size();k++)
                   for(int q=0;q<v[j+1].size();q++)
                       g[v[j][k]].push_back(v[j+1][q]);
            }
        }
    }
    for(i=0;i<tot;i++){
        if(!f) break;
        if(visited[i]==0) dfs(i);
    }
    if(!f) printf("-1\n");
    else
    for(i=ans.size()-1;i>=0;i--)
        if(ans[i]<m) printf("%d ",ans[i]+1);
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#define ll long long
const int N=100001;
using namespace std;

pair<int,int> a[N];
set<int> g[N];
vector<int> v1,v2,v;
int vis[N],m;

bool dfs(int x){
     vis[x]=1;
     set<int>::iterator it;
     for(it=g[x].begin();it!=g[x].end();it++)
         if(vis[*it]<0){
           if(!dfs(*it)) return false;
         }
         else if(vis[*it]==1) return false;
     vis[x]=2;
     if(x<m) v.push_back(x);
     return true;
}

int main(){
    int n,i,j,k,p;
    scanf("%d%d",&n,&m);
    int tot=m;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[j].first);
            a[j].second=j;
        }
        sort(a,a+m);
        j=0;
        while(a[j].first==-1 && j<m) j++;
        v1.clear();
        if(j<m)
        {  v1.push_back(a[j].second);
           while(j<m-1 && a[j+1].first==a[j].first)
           {  j++;
              v1.push_back(a[j].second);
           }
        }
        j++;
        while(j<m)
        {  v2.clear();
           do{
              v2.push_back(a[j].second);j++;}
           while(j<m && a[j].first==a[j-1].first);
           for(k=0;k<v1.size();k++)
              g[v1[k]].insert(tot);
           for(k=0;k<v2.size();k++)
              g[tot].insert(v2[k]);
           tot++;
        }
    }
    memset(vis,-1,sizeof(vis));
    bool ok=true;
    for(i=0;i<tot;i++)
        if(vis[i]<0)
          if(!dfs(i)){ok=false;break;}
    if(!ok) printf("-1\n");
    else
    {  for(i=v.size()-1;i>=0;i--)
           printf("%d ",v[i]+1);
    }
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#define ll long long
const int N=100001;
using namespace std;

pair<int,int> a[N];
set<int> g[N];
vector<int> v1,v2,v;
int vis[N],m;

bool dfs(int x){
     vis[x]=1;
     set<int>::iterator it;
     for(it=g[x].begin();it!=g[x].end();it++)
         if(vis[*it]<0){
           if(!dfs(*it)) return false;
         }
         else if(vis[*it]==1) return false;
     vis[x]=2;
     if(x<m) v.push_back(x);
     return true;
}

int main(){
    int n,i,j,k,p;
    scanf("%d%d",&n,&m);
    int tot=m;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[j].first);
            a[j].second=j;
        }
        sort(a,a+m);
        j=0;
        while(a[j].first==-1 && j<m) j++;
        v1.clear();
        if(j<m)
        {  v1.push_back(a[j].second);
           while(j<m-1 && a[j+1].first==a[j].first)
           {  j++;
              v1.push_back(a[j].second);
           }
        }
        j++;
        while(j<m)
        {  v2.clear();
           do{
              v2.push_back(a[j].second);j++;}
           while(j<m && a[j].first==a[j-1].first);
           for(k=0;k<v1.size();k++)
              g[v1[k]].insert(tot);
           for(k=0;k<v2.size();k++)
              g[tot].insert(v2[k]);
           tot++;
           v1=v2;
        }
    }
    memset(vis,-1,sizeof(vis));
    bool ok=true;
    for(i=0;i<tot;i++)
        if(vis[i]<0)
          if(!dfs(i)){ok=false;break;}
    if(!ok) printf("-1\n");
    else
    {  for(i=v.size()-1;i>=0;i--)
           printf("%d ",v[i]+1);
    }
    //system("pause");
    return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#define ll long long
using namespace std;

int n,m;
vector<pair<int,int> > r;
vector<int> g[150005],p;
vector<vector<int> > v;
vector<int> ans;
int visited[150005];
bool f=true;

void dfs(int x){
     visited[x]=1;
     for(int i=0;i<g[x].size();i++){
         if(visited[g[x][i]]==0) dfs(g[x][i]);
         else if(visited[g[x][i]]==1) {f=false;return;}
         if(!f) return;
     }

     visited[x]=2;
     ans.push_back(x);
}

int main(){
    scanf("%d%d",&n,&m);
    int i,j,x;
    int tot=m;
    for(i=0;i<n;i++)
    {   r.clear();
        for(j=0;j<m;j++)
        {   scanf("%d",&x);
            if(x!=-1) r.push_back(make_pair(x,j));
        }
        sort(r.begin(),r.end());
        v.clear();
        for(j=0;j<r.size();j++)
        {   p.clear();
            p.push_back(r[j].second);
            while(j<m-1 && r[j+1].first==r[j].first) {j++;p.push_back(r[j].second);}
            v.push_back(p);
        }
        for(j=0;j<v.size();j++)
        {   if(j+1==v.size()) break;
            if(v[j].size()>=2 && v[j+1].size()>=2)
            {  tot++;
               for(int k=0;k<v[j].size();k++)
                   g[v[j][k]].push_back(tot-1);
               for(int k=0;k<v[j+1].size();k++)
                   g[tot-1].push_back(v[j+1][k]);
            }
            else
            {  for(int k=0;k<v[j].size();k++)
                   for(int q=0;q<v[j+1].size();q++)
                       g[v[j][k]].push_back(v[j+1][q]);
            }
        }
    }
    for(i=0;i<tot;i++){
        if(!f) break;
        if(visited[i]==0) dfs(i);
    }
    if(!f) printf("-1\n");
    else
    for(i=ans.size()-1;i>=0;i--)
        if(ans[i]<m) printf("%d ",ans[i]+1);
    //system("pause");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1ull << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> T round_up(T a, T b) { return (a + b - 1) / b; }

template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }

template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }

template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

#define F first
#define S second

// トポロジカルソート
bool topo_dfs(int v, const vector<vector<int> >& g, vector<int>& color, vector<int>& order)
{
    color[v] = 1;
    for (int i = 0; i < (int)g[v].size(); ++i)
    {
        int to = g[v][i];
        if (color[to] == 2)
            continue;
        else if (color[to] == 1)
            return false;
        else if (!topo_dfs(to, g, color, order))
            return false;
    }
    color[v] = 2;

    order.push_back(v);
    return true;
}
// O(V + E)
// impossible -> return empty vector
vector<int> topological_sort(const vector<vector<int> >& g)
{
    const int n = g.size();

    vector<int> color(n);
    vector<int> order;

    for (int i = 0; i < n; ++i)
        if (color[i] == 0 && !topo_dfs(i, g, color, order))
            return vector<int>();
    reverse(all(order));
    return order;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n)
        input(a[i], m);

    vector<pint> v;
    vector<vector<int> > g(3 * m * n);
    int p = m;
    rep(y, n)
    {
        v.clear();
        rep(x, m)
            if (a[y][x] != -1)
                v.pb(pint(a[y][x], x));
        sort(all(v));

        if (v.size() >= 2)
        {
            int next = p++;
            int prev = p++;
            for (int i = v.size() - 1; i >= 0; )
            {
                int j;
                for (j = i; j >= 0 && v[j].first == v[i].first; --j)
                {
                    g[prev].pb(v[j].second);
                    g[v[j].second].pb(next);
                }
                i = j;
                next = prev;
                prev = p++;
            }
        }
    }

    vector<int> order = topological_sort(g);
    if (order.empty())
        cout << -1 << endl;
    else
    {
        vector<int> res;
        rep(i, order.size())
            if (order[i] < m)
                res.pb(order[i] + 1);
        print(res);
    }
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1ull << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> void uniq(T& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }

template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }

template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

// トポロジカルソート
// O(V + E)
bool topological_sort(const vector<vector<int> >& g, vector<int>& order)
{
    const int n = g.size();
    order.clear();
    // order.reserve(n);

    vector<int> indegree(n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < (int)g[i].size(); ++j)
            ++indegree[g[i][j]];

    queue<int> q;
    for (int i = 0; i < n; ++i)
        if (indegree[i] == 0)
            q.push(i);

    while (!q.empty())
    {
        int v = q.front();
        q.pop();

        order.push_back(v);

        for (int i = 0; i < (int)g[v].size(); ++i)
            if (--indegree[g[v][i]] == 0)
                q.push(g[v][i]);
    }

    return (int)order.size() == n;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n)
        input(a[i], m);

    vector<pint> v;
    vector<vector<int> > g(3 * m * n);
    int p = m;
    rep(y, n)
    {
        v.clear();
        rep(x, m)
            if (a[y][x] != -1)
                v.pb(pint(a[y][x], x));
        sort(all(v));

        if (v.size() >= 2)
        {
            int next = p++;
            int prev = p++;
            for (int i = v.size() - 1; i >= 0; )
            {
                int j;
                for (j = i; j >= 0 && v[j].first == v[i].first; --j)
                {
                    g[prev].pb(v[j].second);
                    g[v[j].second].pb(next);
                }
                i = j;
                next = prev;
                prev = p++;
            }
        }
    }

    vector<int> order;
    if (!topological_sort(g, order))
        cout << -1 << endl;
    else
    {
        vector<int> res;
        rep(i, order.size())
            if (order[i] < m)
                res.pb(order[i] + 1);
        print(res);
    }
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1ull << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> T round_up(T a, T b) { return (a + b - 1) / b; }

template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }

template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }

template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

#define F first
#define S second

// トポロジカルソート
bool topo_dfs(int v, const vector<vector<int> >& g, vector<int>& color, vector<int>& order)
{
    color[v] = 1;
    for (int i = 0; i < (int)g[v].size(); ++i)
    {
        int to = g[v][i];
        if (color[to] == 2)
            continue;
        else if (color[to] == 1)
            return false;
        else if (!topo_dfs(to, g, color, order))
            return false;
    }
    color[v] = 2;

    order.push_back(v);
    return true;
}
// O(V + E)
// impossible -> return empty vector
vector<int> topological_sort(const vector<vector<int> >& g)
{
    const int n = g.size();

    vector<int> color(n);
    vector<int> order;

    for (int i = 0; i < n; ++i)
        if (color[i] == 0 && !topo_dfs(i, g, color, order))
            return vector<int>();
    reverse(all(order));
    return order;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n)
        input(a[i], m);

    vector<pint> v;
    vector<vector<int> > g(3 * m * n);
    int p = n;
    rep(y, n)
    {
        v.clear();
        rep(x, m)
            if (a[y][x] != -1)
                v.pb(pint(a[y][x], x));
        sort(all(v));

        int next = p++;
        int prev = p++;
        if (v.size() >= 2)
        {
            for (int i = n - 1; i >= 0; --i)
            {
                int j;
                for (j = i; j >= 0 && v[j].first == v[i].first; --j)
                {
                    g[v[j].second].pb(next);
                    g[prev].pb(v[j].second);
                }
                i = j;
                next = prev;
                prev = p++;
            }
        }
    }

    vector<int> order = topological_sort(g);
    if (order.empty())
        cout << -1 << endl;
    else
    {
        vector<int> res;
        rep(i, order.size())
            if (order[i] < m)
                res.pb(order[i] + 1);
        print(res);
    }
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1ull << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> void uniq(T& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }

template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }

template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

// トポロジカルソート
// O(V + E)
bool topological_sort(const vector<vector<int> >& g, vector<int>& order)
{
    const int n = g.size();
    order.clear();
    order.reserve(n);

    vector<int> indegree(n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < (int)g[i].size(); ++j)
            ++indegree[g[i][j]];

    queue<int> q;
    for (int i = 0; i < n; ++i)
        if (indegree[i] == 0)
            q.push(i);

    while (!q.empty())
    {
        int v = q.front();
        q.pop();

        order.push_back(v);

        for (int i = 0; i < (int)g[v].size(); ++i)
            if (--indegree[g[v][i]] == 0)
                q.push(g[v][i]);
    }

    return (int)order.size() == n;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n)
        input(a[i], m);

    vector<pint> v;
    vector<vector<int> > g(3 * m * n);
    int p = m;
    rep(y, n)
    {
        v.clear();
        rep(x, m)
            if (a[y][x] != -1)
                v.pb(pint(a[y][x], x));
        sort(all(v));

        if (v.size() >= 2)
        {
            int next = p++;
            int prev = p++;
            for (int i = v.size() - 1; i >= 0; )
            {
                int j;
                for (j = i; j >= 0 && v[j].first == v[i].first; --j)
                {
                    g[prev].pb(v[j].second);
                    g[v[j].second].pb(next);
                }
                i = j;
                next = prev;
                prev = p++;
            }
        }
    }

    vector<int> order;
    if (!topological_sort(g, order))
        cout << -1 << endl;
    else
    {
        vector<int> res;
        rep(i, order.size())
            if (order[i] < m)
                res.pb(order[i] + 1);
        print(res);
    }
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1ull << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> T round_up(T a, T b) { return (a + b - 1) / b; }

template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }

template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }

template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }

template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)

bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

#define F first
#define S second

// トポロジカルソート
bool topo_dfs(int v, const vector<vector<int> >& g, vector<int>& color, vector<int>& order)
{
    color[v] = 1;
    for (int i = 0; i < (int)g[v].size(); ++i)
    {
        int to = g[v][i];
        if (color[to] == 2)
            continue;
        else if (color[to] == 1)
            return false;
        else if (!topo_dfs(to, g, color, order))
            return false;
    }
    color[v] = 2;

    order.push_back(v);
    return true;
}
// O(V + E)
// impossible -> return empty vector
vector<int> topological_sort(const vector<vector<int> >& g)
{
    const int n = g.size();

    vector<int> color(n);
    vector<int> order;

    for (int i = 0; i < n; ++i)
        if (color[i] == 0 && !topo_dfs(i, g, color, order))
            return vector<int>();
    reverse(all(order));
    return order;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n)
        input(a[i], m);

    vector<pint> v;
    vector<vector<int> > g(m);
    rep(i, n)
    {
        v.clear();
        rep(j, m)
            if (a[i][j] != -1)
                v.pb(pint(a[i][j], j));
        sort(all(v));

        if (v.size() >= 2)
        {
            int next = v.size() - 1;
            revrep(i, v.size() - 2)
            {
                if (v[i].first < v[i + 1].first)
                {
                    g[v[i].second].pb(v[next].second);
                    next = i;
                }
                else if (v[i].first == v[i + 1].first)
                {
                    if (v[i].first != v[next].first)
                        g[v[i].second].pb(v[next].second);
                }
            }
        }
    }

    vector<int> order = topological_sort(g);
    if (order.empty())
        cout << -1 << endl;
    else
    {
        rep(i, m)
            ++order[i];
        print(order);
    }
}