#include <iostream>
#include <algorithm>
using std::cout;
using std::cin;
using std::max;

const int maxn = 1000;

int n, m;
//A[i][j] is the number at square (i, j). C arrays are 0 based hence the extra size.
int A[maxn+1][maxn+1];

//D[i][j] is the maximum sum of numbers a grumkin can collect going from (1, 1) to (i, j)
int D[maxn+1][maxn+1];

int main() {
  cin >> n >> m;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      cin >> A[i][j];

  //First row is special (base case)
  D[1][1] = A[1][1];
  for(int j=2;j<=m;j++){
    D[1][j] = D[1][j-1] + A[1][j];
    for(int l=1;l<j;l++)
      if((j % l)==0) //If l | j
	D[1][j] = max(D[1][j], D[1][l] + A[1][j]);
  }
  //Recursion:
  for(int i=2;i<=n;i++){
    //We want to compute D[i][1]: First column is also a bit special.
    D[i][1] = D[i-1][1] + A[i][1];
    for(int l=1;l<=m;l++)
      D[i][1] = max(D[i][1], D[i-1][l] + A[i][1]);

    for(int j=2;j<=m;j++){
      //We want to compute D[i][j]. 
      //Either we came here from last row or column:
      D[i][j] = max(D[i-1][j], D[i][j-1]) + A[i][j];
      //Or from same row but a column number which divided j:
      for(int l=1;l<j;l++)
	if((j % l)==0) //If l | j
	  D[i][j] = max(D[i][j], D[i][l] + A[i][j]);
    }
  }
  cout << D[n][m] << '\n';
}

