#include<iostream>
#include<algorithm>
const int sz = 210;
struct bigInt {
int num[75], len;
bigInt() {
std::fill(num, num + sz, 0);
len = 0;
}
bigInt& operator=(const int x) {
int cx = x;
while (cx != 0) {
num[++len] = cx % 10;
cx /= 10;
}
return *this;
}
bigInt operator+(const bigInt &a) {
bigInt c;
c.len = std::max(len, a.len);
int x = 0;
for (int i = 1; i <= c.len; i++) {
c.num[i] = num[i] + a.num[i] + x;
x = c.num[i] / 10;
c.num[i] %= 10;
}
if (x > 0)
c.num[++c.len] = x;
return c;
}
bigInt operator*(const int &a) {
bigInt c;
c.len = len; int x = 0;
for (int i = 1; i <= c.len; i++) {
c.num[i] = num[i] * a + x;
x = c.num[i] / 10;
c.num[i] %= 10;
}
while (x > 0)
c.num[++c.len] = x % 10, x /= 10;
return c;
}
bool operator<(const bigInt &a) const {
if (len > a.len)
return true;
else if (len < a.len)
return false;
for (int i = a.len; i; i--) {
if (num[i] > a.num[i])
return true;
else if (num[i] < a.num[i])
return false;
}
return false;
}
} f[sz][sz], pow[sz], ans;
std::ostream& operator<<(std::ostream& out, const bigInt a) {
for (int i = a.len; i; i--) std::cout << a.num[i];
return out;
}
int arr[sz];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
pow[0].num[1] = 1, pow[0].len = 1;
for (int i = 1; i <= m + 2; i++) pow[i] = pow[i - 1] * 2;
while (n--) {
for (int i = 1; i <= m; i++)
std::fill(f[i] + 1, f[i] + m + 1, 0), std::cin >> arr[i];
for (int i = 1; i <= m; i++) f[i][i] = pow[m] * arr[i];
for (int p = 1; p < m; p++) {
for (int i = 1; i + p <= m; i++) {
int j = i + p;
f[i][j] = std::min(f[i][j], f[i + 1][j] + pow[m - p] * arr[i]);
f[i][j] = std::min(f[i][j], f[i][j - 1] + pow[m - p] * arr[j]);
}
}
ans = ans + f[1][m];
}
std::cout << ans;
return 0;
}