#include <bits/stdc++.h>
#include "code.h"

#define MAXN 1010
using namespace std;

int a[MAXN][MAXN],maxv[MAXN],minc[MAXN],maxvc[MAXN],mincc[MAXN];
//int Pitaj(int i, int j);
vector<int> Nadji(int N, int K){
    vector<int> res;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)
            a[i][j]=Pitaj(i,j);
    }
     for(int i=0;i<N;i++){
        maxv[i]=a[i][0];
        for(int j=1;j<N;j++){
            if(a[i][j]>maxv[i]){
                maxv[i]=a[i][j];
                maxvc[i]=0;
                continue;
            }
            if(a[i][j]==maxv[i]){
                maxvc[i]=-1;
                continue;
            }
        }
    }
    for(int j=0;j<N;j++){
        minc[j]=a[0][j];
        for(int i=1;i<N;i++){
            if(a[i][j]<minc[j]){
                minc[j]=a[i][j];
                mincc[j]=0;
                continue;
            }
            if(a[i][j]==minc[j]){
                mincc[j]=-1;
                continue;
            }
        }
    }
     for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(a[i][j]==maxv[i] && a[i][j]==minc[j]&& mincc[j]==0 && maxvc[i]==0){
                res.push_back(i+1);
                res.push_back(j+1);
                //cout<<i+1<<" "<<j+1<<endl;
                i=N;
                break;
            }
        }
    }
    if(res.empty()){
        res.push_back(-1);
    }
    return res;
}