#!/usr/bin/env python3
h, w = map(int, input().split())
plots, best = [list(map(int, input().split())) for _ in range(h)], (1000000, -1)
neighs = [[[min((abs(neigh - dest), abs(neigh - plots[y][x]), xx, yy, neigh) for xx, yy, neigh in
                ((xx, yy, plots[yy][xx]) for xx, yy in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)) if
                 0 <= xx < w and 0 <= yy < h)) for x in range(w)] for y in range(h)] for dest in range(1, w * h + 1)]


def find_path(kiosk_x, kiosk_y, kiosk, dest):
    seen, x, y, curr = set(), kiosk_x, kiosk_y, kiosk
    while (x, y) not in seen:
        seen.add((x, y))
        _, _, x, y, curr = neighs[dest - 1][y][x]
        if curr == dest: return len(seen)
    return 1000000


for kiosk_y in range(h):
    for kiosk_x in range(w):
        kiosk = plots[kiosk_y][kiosk_x]
        longest = max(find_path(kiosk_x, kiosk_y, kiosk, dest) for dest in range(1, w * h + 1) if dest != kiosk)
        best = min(best, (longest, kiosk))

print("impossible") if best[1] == -1 else print(*best[::-1])
