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;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec)is>>x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i, vec.size()) {
        if(i) os << " ";
        os << vec[i];
    }
    return os;
}

struct Edge {
    ll to, cap, rev;
};
vector< vector<Edge> > G;

void add_edge(ll from, ll to, ll cap) {
    G[from].pb({to, cap, (ll)G[to].size()});
    G[to].pb({from, 0, (ll)G[from].size()-1});
}
ll dfs(ll v, ll t, ll f, const vector<ll>& dist) {
    if (v == t) return f;
    EACH(e, G[v]) {
        if (e.cap > 0 && dist[e.to] == dist[v]+1) {
            ll d = dfs(e.to, t, min(f, e.cap), dist);
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
vector<ll> bfs(ll s) {
    vector<ll> res(G.size(), linf);
    res[s] = 0;
    queue<ll> Q; Q.push(s);
    while ( !Q.empty() ) {
        ll v = Q.front(); Q.pop();
        EACH(e, G[v]) {
            if (e.cap > 0 && res[e.to] == linf) {
                res[e.to] = res[v]+1;
                Q.push(e.to);
            }
        }
    }
    return res;
}
ll max_flow(ll s, ll t) {
    ll res = 0;
    while (1) {
        vector<ll> dist = bfs(s);
        if (dist[t] == linf) break;
        while (1) {
            ll f = dfs(s, t, linf, dist);
            if (f == 0) break;
            res += f;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    int v1 = m / n;
    int v2 = v1 + (m % n == 0 ? 0 : 1);
    cout << v2-v1 << endl;
    vector< vector<ll> > H(n, vector<ll>(m)); cin >> H;
    ll ss = n + m, s = ss+1, t = s+1;
    G.resize(t+1);
    REP(i, m) {
        add_edge(n+i, t, 1);
    }
    REP(i, n) {
        add_edge(s, i, v1);
        add_edge(ss, i, 1);
    }
    add_edge(s, ss, m-n*v1);
    map<ll, vector<P>> ev;
    REP(i, n) REP(j, m) {
        ev[H[i][j]].pb({i, j});
    }
    ll f = 0;
    ll ans = linf;
    EACH(dt, ev) {
        EACH(p, dt.second) {
            assert(dt.first == H[p.first][p.second]);
            add_edge(p.first, n+p.second, 1);
        }
        f += max_flow(s, t);
        if (f == m) {
            ans = dt.first;
            break;
        }
    }
    cout << ans << endl;
}