#include "code.h"
#include <bits/stdc++.h>
#define MAX_N 1005
#define INF 1000000001
using namespace std;
//int Pitaj(int i, int j);

int H[MAX_N][MAX_N];
int pitaj(int i, int j){
    if(H[i][j]==-1)H[i][j]=Pitaj(i+1, j+1);
    return H[i][j];
}
int N;
int maxR[MAX_N], minC[MAX_N];//index maksimalnog elementa u redu ili minimalnog u koloni
int findR(int row){
    int maxi=0, argmax=-1;
    for(int i=0; i<N; ++i){
        if(pitaj(row, i)>maxi){
            maxi=pitaj(row, i);
            argmax=i;
        }
    }//printf("findrow(%d)=%d\n", row, argmax);
    return argmax;
}

int findC(int col){
    int mini=INF, argmax=-1;
    for(int i=0; i<N; ++i){
        if(pitaj(i, col)<mini){
            mini=pitaj(i, col);
            argmax=i;
        }
    }//printf("findcol(%d)=%d\n", col, argmax);
    return argmax;
}
vector<int> Nadji(int n, int K)
{
    N=n;
	memset(H, -1, sizeof(H));
	memset(maxR, -1, sizeof(maxR));
	memset(minC, -1, sizeof(minC));
	int cur=0;
	while(1){
        maxR[cur]=findR(cur);
        if(minC[maxR[cur]]==-1){
            minC[maxR[cur]]=findC(maxR[cur]);
            if(minC[maxR[cur]]==cur){
                vector<int> out;
                out.push_back(cur+1);
                out.push_back(maxR[cur]+1);
                return out;
            }
            cur=minC[maxR[cur]];
            continue;
        }
        else{
            if(minC[maxR[cur]]==cur){
                vector<int> out;
                out.push_back(cur+1);
                out.push_back(maxR[cur]+1);
                return out;
            }
            else{
                vector<int> out;
                out.push_back(0);
                out.push_back(0);
                return out;
            }
        }
    }
    vector<int> out;
	return out;
}