← Home
```go
package main

import (
	"fmt"
	"io"
	"math/bits"
	"os"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	pos := 0
	nextInt := func() int {
		for pos < len(data) && data[pos] <= ' ' {
			pos++
		}
		val := 0
		for pos < len(data) && data[pos] > ' ' {
			val = val*10 + int(data[pos]-'0')
			pos++
		}
		return val
	}

	n := nextInt()
	m := nextInt()

	a := make([][]int, n)
	for i := 0; i < n; i++ {
		row := make([]int, m)
		for j := 0; j < m; j++ {
			row[j] = nextInt()
		}
		a[i] = row
	}

	const INF = 1 << 30

	w := make([]int, n*n)
	for i := 0; i < n; i++ {
		ai := a[i]
		baseI := i * n
		for j := i + 1; j < n; j++ {
			aj := a[j]
			mn := INF
			for c := 0; c < m; c++ {
				d := ai[c] - aj[c]
				if d < 0 {
					d = -d
				}
				if d < mn {
					mn = d
				}
			}
			w[baseI+j] = mn
			w[j*n+i] = mn
		}
	}

	v := make([]int, n*n)
	if m == 1 {
		for i := range v {
			v[i] = INF
		}
	} else {
		for i := 0; i < n; i++ {
			ai := a[i]
			baseI := i * n
			for j := 0; j < n; j++ {
				aj := a[j]
				mn := INF
				for c := 0; c < m-1; c++ {
					d := ai[c] - aj[c+1]
					if d < 0 {
						d = -d
					}
					if d < mn {
						mn = d
					}
				}
				v[baseI+j] = mn
			}
		}
	}

	all := 1 << n
	fullMask := all - 1
	dp := make([]int, all*n)
	ans := 0

	for s := 0; s < n; s++ {
		for i := range dp {
			dp[i] = -1
		}

		startMask := 1 << s
		dp[startMask*n+s] = INF

		for mask := 0; mask < all; mask++ {
			if mask&startMask == 0 {
				continue
			}
			base := mask * n
			rem := fullMask ^ mask

			for bitsLast := mask; bitsLast > 0; bitsLast &= bitsLast - 1 {
				last := bits.TrailingZeros(uint(bitsLast))
				cur := dp[base+last]
				if cur < 0 {
					continue
				}
				rowBase := last * n

				for bitsNext := rem; bitsNext > 0; bitsNext &= bitsNext - 1 {
					nxt := bits.TrailingZeros(uint(bitsNext))
					nv := w[rowBase+nxt]
					if cur < nv {
						nv = cur
					}
					idx := ((mask | (1 << nxt)) * n) + nxt
					if nv > dp[idx] {
						dp[idx] = nv
					}
				}
			}
		}

		fullBase := fullMask * n
		for last := 0; last < n; last++ {
			cur := dp[fullBase+last]
			if cur < 0 {
				continue
			}
			cand := cur
			if v[last*n+s] < cand {
				cand = v[last*n+s]
			}
			if cand > ans {
				ans = cand
			}
		}
	}

	fmt.Print(ans)
}
```