n = gets.to_i
abc = []
n.times { |i|
  abc[i] = gets.split.map(&:to_i)
}

dp = []
dp[0] = abc[0].max
ind = abc[0].index(dp[0])

1.upto(n-1) { |i|
  mx = 0
  next_ind = -1
  abc[i].each_index { |j|
    if ind != j
      if (abc[i][j] > mx)
        next_ind = j
        mx = abc[i][j]
      end
    end
  }
  dp[i] = dp[i-1] + mx
  ind = next_ind

}

p dp[n-1]
