Problem: BackGround

In the Demon's Plan, 108 demons who control the desire are competing in the programming contest day and night. The organizer, Patron, is trying to invite the demons to "Rix-Magna", a place where all the souls gather. Patron wants to send an invitation to a demon who hasn't sent an invitation yet, but he decides to let his familiars do it because the demons are all over the world and it's a hassle to go by himself. Patrons are smart and are trying to allocate which familiars are in charge of which demons so that the familiars work more equally.

Problem

There are N familiars and M demons. The distance between familiar i and devil j is Hi j.

I want each demon to have one familiar. Which familiar will visit which demon will be assigned according to the following conditions.

1. Minimize the maximum difference in the number of demons visited per familiar.
2. Minimize the maximum distance between the visiting demon and the familiar familiar after satisfying 1.



Output the maximum difference in the number of visiting demons per familiar on the first line, and the maximum distance between the demon and the familiar in charge on the second line.

Constraints

* 1 ≤ N ≤ 108
* 1 ≤ M ≤ 108
* 1 ≤ Hi j ≤ 109 (0 ≤ i <N, 0 ≤ j <M) (distance from familiar i to devil j)

Input

The input is given in the following format.


N M
H0 0 H0 1… H0 M−1
H1 0 H1 1… H1 M-1
..
..
HN−1 0 HN−1 1… HN−1 M−1


On the first line, the number N of familiars and the number M of demons are given as integers separated by blanks. The distance between the familiar and the devil is given as an integer in the following N lines. Hij represents the distance between familiar i and devil j.

Output

According to the conditions of the problem statement, output the maximum difference in the number of visiting demons per familiar on the first line, and the maximum distance between the demon and the familiar in charge on the second line.

Examples

Input

3 3
1 2 3
2 1 2
3 2 1


Output

0
1


Input

3 5
1 2 3 4 5
5 4 3 2 1
4 3 2 1 5


Output

1
2

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 300
#define INF (1e8)
struct edge{ int to,cap,rev; };
 
int V,E;
vector<edge> G[MAX_V];
bool used[MAX_V];
 
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
 
int dfs(int v,int t,int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,false,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int N,M;
int t[200][200];

bool check(int mid){
  for(int i=0;i<MAX_V;i++)G[i].clear();
  
  V=N+M+3;
  int si=V-3;
  int ti=V-2;
  int xx=V-1;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(t[i][j] > mid)continue;
      add_edge(i,N+j,1);
    }
  }
  for(int i=0;i<N;i++){
    int cap=M/N;
    add_edge(si, i,cap);
  }
  for(int i=0;i<M;i++){
    add_edge(N+i,ti,1);
  }
  if(M%N>0){
    add_edge(si,xx,M%N);
    for(int i=0;i<N;i++){
      add_edge(xx,i,1);
    }
  }
  if( max_flow(si,ti) == M )return true;
  return false;
}

int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>t[i][j];
    }
  }
  if(M%N==0)cout<<0<<endl;
  else cout<<1<<endl;
  
  int L=1,R=1e9,M;
  while(L<R){
    M=(L+R)/2;
    if(check(M))R=M;
    else L=M+1;
  }
  cout<<L<<endl;
  return 0;
}