n, m = map(int, input().split()) if n == 1: print(0) else: a = [list(map(int, input().split())) for _ in range(n)] # Calculate the minimum cost of fully demolishing a single column full_column_min = float('inf') for j in range(m): total = sum(a[i][j] for i in range(n)) if total < full_column_min: full_column_min = total # Calculate the sum of minimum costs for each consecutive floor pair total_pair = 0 for i in range(n - 1): min_pair = float('inf') for j in range(m): current = a[i][j] + a[i + 1][j] if current < min_pair: min_pair = current total_pair += min_pair print(min(full_column_min, total_pair))