n,k = gets.split.map(&:to_i)
h = n.times.map{gets.split.map(&:to_i)}
a = n.times.map{Array.new(3,0)}
3.times{|i| a[0][i] = h[0][i]}

(n-1).times{|i|
  3.times{|j|
    1.upto(2){|k|
      if i+j<=n && a[i+1][j] < a[i][j-k]+h[i+1][j]
        a[i+1][j] = a[i][j-k]+h[i+1][j]
      end
    }
  }
}

p a[n-1].max